Ich habe ein kleines Problem. Ich habe eine 1 RichTextBox und 2 Buttons.Substract Flag von FontStyle (Toggling FontStyles) [C#]
Ich habe diese 2 Tasten für "toggle Bold FStyle" und "toggle Italic FStyle".
Ich möchte FontStyles umschalten, ohne andere FontStyles zu beeinflussen. Ich hoffe du verstehst mich.
Im Folgenden Code funktioniert, wenn Fontstyles kombiniert aber funktioniert nicht, wenn seperating/Substraktion Fontstyles.
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font, (richTextBox1.SelectionFont.Bold == false ? richTextBox1.SelectionFont.Style | FontStyle.Bold : richTextBox1.SelectionFont.Style));
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font, (richTextBox1.SelectionFont.Italic == false ? richTextBox1.SelectionFont.Style | FontStyle.Italic : richTextBox1.SelectionFont.Style));
}
- Ich mache ausgewählten Text Bold
- wähle ich machen Text Kursiv
- Ich möchte Kursiv entfernen, während Bold noch aktiv ist (oder umgekehrt)
Ein ähnlicher Lösungsansatz gilt auch für TextBox-Steuerelemente. Siehe meinen Kommentar in der Antwort unten. –