dotnet / dotnet/winforms

RichTextbox font family not applied to new text

Open
#8,902 2 comments 1 reaction 0 assignees View on GitHub
area-controls-RichEdit priority-3
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .NET version

Tested in 7.0, 6.0 and .NET framework 4.8.

### Did it work in .NET Framework?

No

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

Not that I know of.

### Issue description

Setting the `Font` or `SelectionFont` property to some font, like `new Font("Arial Black", 11.5f, FontStyle.Italic)`, programtically entered text, either through `AppendText(...)` or modifying the `Text` property directly, displays with the chosen font applied. When entering new text however, be it by simply appending at the end, selecting all or part of the text and then typing new text, or typing in between the text already present, will have the expected font size and style applied, but a default font family.

I tried to figure out where new text input is processed in the `RichTextBox` and `TextBoxBase` classes, but I couldn't manage to find it. If anyone could point me to the source code for that, please do so!

https://user-images.githubusercontent.com/78665317/227747410-359ce9aa-37c6-4ab6-a3b3-95263a959f81.mp4

### Steps to reproduce

```c#
var rtb = new RichTextBox
{
Font /* or SelectionFont, same behaviour */ = new Font("Arial Black", 11.5f, FontStyle.Italic), // could be any font
};

rtb.AppendText("Sample text");
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.