Jag har nu länge och väl försökt att lösa mitt problem, men jag känner att
jag är tvungen att störa er.
Problem.
Jag har en toolstrip med en del formateringsknappar, fet kursiv mm.
Som det nu är, så när jag trycker på någon av knapparna, så får jag fram
önskad effekt, men jag kan inte "stänga" av denna effekt. (Kryptiskt?).
private void makeBold()
{
if (rTBDoc.SelectionFont.Bold == true)
{
System.Drawing.Font currentFont = rTBDoc.SelectionFont;
System.Drawing.FontStyle newFontStyle;
newFontStyle = rTBDoc.SelectionFont.Style ^ FontStyle.Regular;
rTBDoc.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
this.bBold.Checked = false;
}
else
{
System.Drawing.Font currentFont = rTBDoc.SelectionFont;
System.Drawing.FontStyle newFontStyle;
newFontStyle = rTBDoc.SelectionFont.Style ^ FontStyle.Bold;
rTBDoc.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
this.bBold.Checked = true;
}
}
private void makeItalic()
{
if (this.rTBDoc.SelectionFont.Italic == true)
{
System.Drawing.Font currentFont = rTBDoc.SelectionFont;
System.Drawing.FontStyle newFontStyle;
newFontStyle = rTBDoc.SelectionFont.Style ^ FontStyle.Regular;
rTBDoc.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
this.bItalic.Checked = false;
}
else
{
System.Drawing.Font currentFont = rTBDoc.SelectionFont;
System.Drawing.FontStyle newFontStyle;
newFontStyle = rTBDoc.SelectionFont.Style ^ FontStyle.Italic;
rTBDoc.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
this.bItalic.Checked = true;
}
}
rTBDoc är min richTextBox.
Jag har även försökt med att ändra ifsatsen, så att den kolla om knappen är
nere, men det hjälper inte. Knapparna styrs så här:
this.bBold.Checked = ((rTBDoc.SelectionFont.Style & FontStyle.Bold) == FontStyle.Bold);
this.bItalic.Checked = ((rTBDoc.SelectionFont.Style & FontStyle.Italic) == FontStyle.Italic);
this.bUnderline.Checked = ((rTBDoc.SelectionFont.Style & FontStyle.Underline) == FontStyle.Underline);
this.bStrikeThrough.Checked = ((rTBDoc.SelectionFont.Style & FontStyle.Strikeout) == FontStyle.Strikeout);
Jag vore väldigt tacksam för lite hjälp :birp