c# - How to stop my bold/italic/underline options changing the text's font back to the default font and size -
in application, have feature allows user change bold/italic/underline styles of text. however, have noticed when user makes text bold, reverts text default size , font , makes bold. undesired mean user have change font , size of text again, undesirable.
currently, code making text bold within application's richtextbox is:
richtextboxprintctrl1.selectionfont = new system.drawing.font(richtextboxprintctrl1.font, richtextboxprintctrl1.selectionfont.style ^ fontstyle.bold);
where going wrong? make text bold, reverts text default size , font... however, colour unaffected.
try using sample code provided msdn:
system.drawing.font currentfont = richtextboxprintctrl1.selectionfont; system.drawing.fontstyle newfontstyle; if (richtextboxprintctrl1.selectionfont.bold == true) { newfontstyle = fontstyle.regular; } else { newfontstyle = fontstyle.bold; } richtextboxprintctrl1.selectionfont = new font( currentfont.fontfamily, currentfont.size, newfontstyle );
edit
as per @abalter suggestion put inside answer sample code write in comment below. code better match asked in question.
if (richtextboxprintctrl1.selectionfont.bold == true) { newfontstyle = currentfont.style ^ fontstyle.regular; } else { newfontstyle = currentfont.style | fontstyle.bold; }
Comments
Post a Comment