Ich habe einen einfachen Texteditor erstellt. Darin ist ein Kombinationsfeld zum Ändern der Schriftfamilie, des Stils und der Farbe verfügbar. Es ist mir gelungen, die Schriftarteigenschaften des ausgewählten Textes zu ändern. Mein CodeC# richttextbox Schrifteigenschaften
private void fontFamilySelectedIndexChanged(object sender, EventArgs e)
{
if (notesCon[currentNotes].SelectedText != "")
{
notesCon[currentNotes].SelectionFont = new Font(fontFamily.SelectedItem.ToString(), notesCon[currentNotes].SelectionFont.Size, notesCon[currentNotes].SelectionFont.Style);
}
}
private void fontStyleSelectedIndexChanged(object sender, EventArgs e)
{
if (notesCon[currentNotes].SelectedText != "")
{
switch (fontStyle.SelectedItem.ToString())
{
case "Bold": notesCon[currentNotes].SelectionFont = new Font(notesCon[currentNotes].SelectionFont.FontFamily, notesCon[currentNotes].SelectionFont.Size, FontStyle.Bold);
break;
case "Italic": notesCon[currentNotes].SelectionFont = new Font(notesCon[currentNotes].SelectionFont.FontFamily, notesCon[currentNotes].SelectionFont.Size, FontStyle.Italic);
break;
case "Regular": notesCon[currentNotes].SelectionFont = new Font(notesCon[currentNotes].SelectionFont.FontFamily, notesCon[currentNotes].SelectionFont.Size, FontStyle.Regular);
break;
case "Strikeout": notesCon[currentNotes].SelectionFont = new Font(notesCon[currentNotes].SelectionFont.FontFamily, notesCon[currentNotes].SelectionFont.Size, FontStyle.Strikeout);
break;
case "Underline": notesCon[currentNotes].SelectionFont = new Font(notesCon[currentNotes].SelectionFont.FontFamily, notesCon[currentNotes].SelectionFont.Size, FontStyle.Underline);
break;
}
}
}
private void fontColorSelectedValueChanged(object sender, EventArgs e)
{
if (notesCon[currentNotes].SelectedText != "")
{
notesCon[currentNotes].SelectionFont = new Font(fontFamily.SelectedItem.ToString(), notesCon[currentNotes].SelectionFont.Size, notesCon[currentNotes].SelectionFont.Style);
notesCon[currentNotes].SelectionColor = fontColor.SelectedItem.Color;
}
}
mein Dilemma:
Jedes Mal, wenn ich versuche, die aktuellen Schriftart Eigenschaften der Rich-Text-Box auf einen neuen zu setzen, ändert es erfolgreich, aber nicht behalten die Schrifteigenschaften des vorherigen Textes. Wie soll ich die Schrifteigenschaften ändern, ohne die vorherigen Schrifteigenschaften des Textes im Rich-Text-Feld zu ändern? Hilfe bitte, Vielen Dank im Voraus!