I can't assign RichTextBox.SelectionFont

zequion 156 Reputation points
2022-08-20T00:52:36.563+00:00

I try to map RichTextBox.Font and RichTextBox.SelectionFont and RichTextBox.SelectionFont doesn't map unit on "Pixel" so font size is different. I have tried different things and nothing works.

System.Windows.Forms.RichTextBox RichTextBox = new System.Windows.Forms.RichTextBox();  
RichTextBox.Font = RichTextBox.SelectionFont = new System.Drawing.Font("Arial", (float)10, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);  

Video:26GCxdyfUrw+

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,010 questions
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2022-08-20T13:14:06.913+00:00

    I think that the authors had a different vision. The font is applied after selecting a text and assigning a value to SelectionFont, not before. For example, you select a text and press a button. The code of the button makes a font and assigns it to SelectionFont. Then the new font becomes visible on the screen. The font will be kept even if you move the caret or select another text.

    In addition, make sure that you assign the font to the visible control, not to an unused object created by new but not added to form.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.