c# - RichTextBox 使用 CFM_COLOR 代码更改字体颜色
问题描述
我正在 Windows 窗体中开发一个文本编辑器,为此我使用 RichTextBox 小部件。I came across a problem where, when selecting different styled text pieces, the selection would return a null value, which prevented me from, let's say, changing the size of a text that has parts of Verdana and Arial in it.
为了解决这个问题,我创建了一个新类来操作 CHARFORMAT 结构,并根据我想要更改的样式发送消息。现在我需要创建一个函数来改变用户选择的字体颜色。为此,我需要 CFM_COLOR 标签,我不知道它是什么,而且我似乎无法在任何地方找到它。
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Color SelectionFontColor
{
set
{
CHARFORMAT cf = new CHARFORMAT();
cf.cbSize = Marshal.SizeOf(cf);
cf.dwMask = CFM_COLOR;
// There might be some missing code
???
SendMessage(Handle, EM_SETCHARFORMAT, SCF_SELECTION, ref cf);
}
}
解决方案
来自referencesource.microsoft.com 上的RichTextBoxConstants.cs:
internal const int CFM_COLOR = 0x40000000;
推荐阅读
- javascript - 使用 getRowStyle 时丢失选择背景颜色
- string - csh/tcsh 如何查找特定字符串是否在变量/文件名中?
- java - Spring 如何自动创建/实例化存储库
- json - 如何在颤动中解密带有gzip编码数据的json响应?
- c# - NuGet:将包依赖项显式列出为项目中的包引用,以便可以卸载它们
- google-apps-script - 谷歌表格 - 在脚本中使用偏移量中的单元格值
- sql - I have a problem removing; of a column with the substring in SQL Server
- javascript - Mousemove events don't trigger
- asp.net - WebForm MVP one view to display different controls after each button click
- java - java.lang.NullPointerException Can't set text from class to activity