Change RichTextBox Font

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi EveryBody

when i execute the code:
Dim rtftext As New RichTextBox
rtftext.Font = New Font("Courier New", 11)
Debug.WriteLine(rtftext.Font.Name & " " & rtftext.Font.Size)
Debug.WriteLine(rtftext.SelectionFont.Name & " " &
rtftext.SelectionFont.Size)
The result is:
Courier New 11
Courier New 11.25
why ist the Font.Size and the SelectionFont.Size not the same?
what can i do that there are the same?
Any help or redirection will be appreciated

regard's

Mario
 
Mario,

The font size is not the only difference. The font's are form different
charsets for example.

I can't explain why is this happens at this moment, but when you set the
Font property the code sends EM_SETCHARFORMAT with wParam SCF_ALL, but when
you read the SelectionFont it sends EM_GETCHARFORMAT with wParam -1, which
is not defined value in the SDK header files (.NET1.x) or 1 (.NET2) which is
the correct value.

Anyways there is something fishy.

In any case it looks like in order to read the font you want from the
SelectionFont property you need to set it there.

My suggestion is when you create the control to set both properties. When
the control is empty the font you set in the SelectionFont will be the one
that is used to type the text. You need to set the Font property as well
though other wise when you press the enter key (start a new paragraph) the
think will not look ok until you start typing.
 
When i set the Font, it fill SelectionFont automatically . When i press Shift
+ arrow right, thenn delete, the Font will be convert to SelectionFont and it
is different.
 
Back
Top