如何在RichEdit控件中更改字符间距?
我尝试使用CHARFORMAT
结构,但正如MSDN所说,sSpacing
在RichEdit控件中没用。而且,SetTextExtra
函数在该控件的hdc中也是无用的。
我还尝试使用该控件的ole接口,ITextFont
接口的SetSpace函数,效果不佳。
有人可以帮助我吗?
谢谢!
答案 0 :(得分:0)
如果你的意思是单个字符之间的字符间距,我不确定你能做什么。如果您正在讨论行之间的间距,请使用PARAFORMAT结构和EM_SETPARAFORMAT消息。
答案 1 :(得分:0)
绝对可以在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;