c# - 一些 Alt 键改变了我的 RichTextBox 字体
问题描述
解决方案
This is the default behavior.
RichTextBox
automatically finds a fallback font to represent those characters that the currently specified Font can't handle.
If not otherwise instructed, it changes the Font
selection with the fallback Font.
Read this rant about the same default behavior of the RichTextBox
ancestor (the RichEdit
control, from which the WinForms
control derives): Don't change the font, dammit!
There are means to change this behavior. At least in the way the RichTextBox
control reports the current Font and Font selection. The C++
code in the previous blog post is one.
A StackOverflow Question/Answer on the subject:
How to force a Win32 RichEdit fallback to SimSun with East Asian text.
But you don't need to fallback to C++
for this.
See the RichTextBox.LanguageOption and the RichTextBoxLanguageOptions flags.
You can insert this line of code right after the InitializeComponent()
proc in your Form
constructor:
richTextBox1.LanguageOption = RichTextBoxLanguageOptions.DualFont;
or
richTextBox1.LanguageOption = RichTextBoxLanguageOptions.DualFont |
RichTextBoxLanguageOptions.UIFonts;
There's a slight difference. See the reference Docs and test this behaviour in your specific context.
If you insert an Unicode symbol that is not handled by the current Font, a fallback is always possible, but the RichTextBox
UI will not change the Font
, not even the SelectionFont
.
And Clipboard.SetText(), Clipboard.GetText() will work as usual.
推荐阅读
- c++ - 您将如何使用标准引号解释指向基类和派生类成员的指针的这种差异?
- bash - Anaconda 环境 bash 前缀太长
- python - 查找日志文件中的模式计数驻留在 zip 文件中而不提取
- sql - 如何使用 SQL 找到每个组的最小值和最大值?
- php - ES256 JWT 在 PHP 中为 Apple AppStoreConenct API 身份验证签名
- java - 了解 JBoss EAP 6.4 (HornetQ) 中的远程 JMS 连接
- sql-server - 在 Linux 中添加 SSL 证书后 SQL Server 服务中断
- mongodb - 如何检查文档中是否存在元素并根据它返回true或false?
- r - R ggplotly重复的传说
- python - 我无法在我的 Emotion.html 中打印变量