RichTextBox在输入特定字符时更改字体。

huangapple go评论70阅读模式
英文:

RichTextBox changes font when certain chars are typed in

问题

我正在制作一个用于控制我自己的Rust游戏服务器的程序,但我发现一个问题,不知道为什么会发生。

我有一个控制台窗口(RichTextBox),当输入特定字符时,它会更改字体。
像**¯\_(ツ**这样的字符会改变文本字体,就像下面的截图中所示:
RichTextBox在输入特定字符时更改字体。

正如您所看到的,就在包含这些奇怪字符的玩家名称之后,字体发生了变化,我不知道该如何修复它。

英文:

I'm making a program to control my own server of the game Rust, but I found a problem that I don't have a clue why it's happening.

I have a console window (RichTextBox) that when certain chars are typed, it changes the font.
Chars like ¯\_(ツ change the text font, like in the screenshot below:
RichTextBox在输入特定字符时更改字体。

As you can see, right after the player name that contains those weird chars, the font changes and I dont know how to fix it.

答案1

得分: 1

这个问题的解决方法在@Jimi指出后变得相当简单。

由于默认字体中不存在日文字符,它会回退到Arial字体(支持这些字符),之后不会再切回默认字体。

为了让仅不支持的字符以Arial字体显示,我使用了下面的代码:

richTextBox1.LanguageOption = RichTextBoxLanguageOptions.DualFont|RichTextBoxLanguageOptions.UIFonts;

在我的InitializeComponent();调用之后。

英文:

The fix for this problem was quite simple to find after @Jimi pointed me out.

Since the japanese chars doesn't exist on the default font, it will fallback to the arial font (which supports the chars) and after that it will not go back to the default font.

To make only the unsupported chars appear in arial font, I've used the code below:

richTextBox1.LanguageOption = RichTextBoxLanguageOptions.DualFont|RichTextBoxLanguageOptions.UIFonts;

Right after my InitializeComponent(); call.

huangapple
  • 本文由 发表于 2023年7月3日 09:39:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定