RichTextBox 使用 CFM_COLOR 代码更改字体颜色
RichTextBox changing Font Color using CFM_COLOR code
我正在 Windows Forms 中开发一个文本编辑器,为此我使用了 RichTextBox 小部件。我遇到了一个问题,在选择不同样式的文本片段时,选择将return一个无效的值,这使我无法更改其中包含Verdana和Arial的文本的大小。
为了解决这个问题,我创建了一个新的 class 来操作 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);
}
}
来自 RichTextBoxConstants.cs 在 referencesource.microsoft.com:
internal const int CFM_COLOR = 0x40000000;
I came across a problem where, when selecting different styled text
pieces, the selection would return a null value
我无法重现您的问题:例如,我 select 使用不同样式的文本,并且我使用 richTextBox1.SelectionColor[ 用橙色为 select 编辑的文本着色 select =17=]
=>
我正在 Windows Forms 中开发一个文本编辑器,为此我使用了 RichTextBox 小部件。我遇到了一个问题,在选择不同样式的文本片段时,选择将return一个无效的值,这使我无法更改其中包含Verdana和Arial的文本的大小。
为了解决这个问题,我创建了一个新的 class 来操作 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);
}
}
来自 RichTextBoxConstants.cs 在 referencesource.microsoft.com:
internal const int CFM_COLOR = 0x40000000;
I came across a problem where, when selecting different styled text pieces, the selection would return a null value
我无法重现您的问题:例如,我 select 使用不同样式的文本,并且我使用 richTextBox1.SelectionColor[ 用橙色为 select 编辑的文本着色 select =17=] =>