How can I format a text selection in bold AND italic?
-
What the suject says... I can format the selection to bold and to italic. but when I want the text bold and italic the formation is set to regular automatically. Thats my code:
newfont = FontStyle.Bold & FontStyle.Italic;
richTextBox1.SelectionFont = new Font(currentfont.FontFamily, currentfont.Size, newfont); -
What the suject says... I can format the selection to bold and to italic. but when I want the text bold and italic the formation is set to regular automatically. Thats my code:
newfont = FontStyle.Bold & FontStyle.Italic;
richTextBox1.SelectionFont = new Font(currentfont.FontFamily, currentfont.Size, newfont);& is AND - a binary operation that returns a 1 in each bit only if the corresponding bit in both operands is 1, and a zero otherwise. So if these are in Binary:
0011 & 1010
Will return 0010 because only the second bit has matching "1"s in the same position. The operation you want is OR : | which returns a 1 is either corresponding bit is 1.
0011 | 1010
Will return 1011. So try:
newfont = FontStyle.Bold | FontStyle.Italic;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
& is AND - a binary operation that returns a 1 in each bit only if the corresponding bit in both operands is 1, and a zero otherwise. So if these are in Binary:
0011 & 1010
Will return 0010 because only the second bit has matching "1"s in the same position. The operation you want is OR : | which returns a 1 is either corresponding bit is 1.
0011 | 1010
Will return 1011. So try:
newfont = FontStyle.Bold | FontStyle.Italic;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
thanks a lot it works do you know how I can say that I will get the currentFontStyle without bold ? so if the selection is bold and italic and now i just want it in italic? i only want the code...
-
thanks a lot it works do you know how I can say that I will get the currentFontStyle without bold ? so if the selection is bold and italic and now i just want it in italic? i only want the code...
Use:
existingStyle & ~FontStyle.Bold
That turns the bit off.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Use:
existingStyle & ~FontStyle.Bold
That turns the bit off.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
perfect thank you so much!
-
perfect thank you so much!
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...