如何更改 RichEdit 控件中的字符间距?
我曾尝试使用该CHARFORMAT结构,但正如 MSDN 所说,sSpacing它在 RichEdit 控件中是无用的。此外,SetTextExtra该控件的hdc中的功能也无用。
而且我也试过用那个控件的ole接口,接口的SetSpace函数ITextFont,无效。
有人可以帮助我吗?
谢谢!
如何更改 RichEdit 控件中的字符间距?
我曾尝试使用该CHARFORMAT结构,但正如 MSDN 所说,sSpacing它在 RichEdit 控件中是无用的。此外,SetTextExtra该控件的hdc中的功能也无用。
而且我也试过用那个控件的ole接口,接口的SetSpace函数ITextFont,无效。
有人可以帮助我吗?
谢谢!
如果您的意思是单个字符之间的字符间距,我不确定您是否可以做任何事情。如果您在谈论行间距,请使用 PARAFORMAT 结构和 EM_SETPARAFORMAT 消息。
绝对适用于 Windows 10 中的 RichEdit v8.5。
确保您使用的是 Windows 类"RICHEDIT50W"(来自MsftEdit.dll)而不是"RichEdit20W"类(来自Riched32.dll):
//Get the ITextDocument interface of the RichEdit control
IUnknown re;
if (SendMessage(RichEdit1.Handle, EM_GetOleInterface, 0, ref (LPARAM)re) == 0)
throw new Exception("Could not get ITextDocument from RichEdit");
ITextDocument doc = re as ITextDocument;
//Increase spacing (positive is expanded)
Single spacing = doc.Selection.Font.Spacing;
spacing += 1;
doc.Selection.Font.Spacing = spacing;
//Decrease spacing (negative is compressed)
spacing = doc.Selection.Font.Spacing;
spacing -= 1;
doc.Selection.Font.Spacing = spacing;
//Reset to normal spacing
doc.Selection.Font.Spacing = 0;