0x64
0x64

Reputation: 122

c# Winform richtextbox font discrepancy

The font property of richtextbox doesn't seem to be working.

        // 
        // textBox_rawdata
        // 
        this.textBox_rawdata.DetectUrls = false;
        this.textBox_rawdata.Font = new System.Drawing.Font("NSimSun", 9F);
        this.textBox_rawdata.HideSelection = false;
        this.textBox_rawdata.Location = new System.Drawing.Point(22, 43);
        this.textBox_rawdata.Name = "textBox_rawdata";
        this.textBox_rawdata.Size = new System.Drawing.Size(368, 68);
        this.textBox_rawdata.TabIndex = 2;
        this.textBox_rawdata.Text = "AAAAAA";

I want the font of the richtextbox to be NSimSun, 9pt. As you can see in the picture, enter image description hereThe first few A's are preset and the last 3 A's are typed in by me. The issues is, the preset characters and any characters generated by the program are correctly displayed as NSimSun, 9pt. But as soon as I start typing in there, the font changes. (Like the last 3 A's)

How can I make the font NSimSun, 9pt for all text?

Upvotes: 1

Views: 183

Answers (2)

user_4685802
user_4685802

Reputation: 155

This might work for you.

this.textBox_rawdata.SelectionFont = new System.Drawing.Font("Tahoma", 12, System.Drawing.FontStyle.Bold)

if you want your font type, size and style to be set once you run your code put this in designer:

 this.textBox_rawdata.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

Upvotes: 4

demonplus
demonplus

Reputation: 5801

Try to set SelectionFont property of richtextbox to System.Drawing.Font("NSimSun", 9F) also.

From MSDN it is:

A Font that represents the font to apply to the current text selection or to text entered after the insertion point.

Upvotes: 0

Related Questions