0

How can I change the character spacing in RichEdit control?

I have tried to use the CHARFORMAT structure, but as MSDN says, the sSpacing is useless in RichEdit control. Moreover, SetTextExtra function is useless in that control's hdc, too.

And I also tried to use the ole interface of that control, the SetSpace function of ITextFont interface, ineffective.

Does anybody could help me?

Thanks!

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219

2 Answers2

0

If you mean character spacing between individual characters, I'm not sure if there is anything you can do. If you are talking about spacing between lines, then use the PARAFORMAT structure and the EM_SETPARAFORMAT message.

Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
  • Thanks for your answer, Joe! I mean how to change to the spacing between two characters, not between two lines. For example, the "hello" word, after changed, it will looks like this, "h e l l o". The spacing between letter 'h' and 'e' could be changed with a variable. – user1444552 Jun 09 '12 at 06:45
0

Definitely works with RichEdit v8.5 in Windows 10.

Be sure you are using the Windows class "RICHEDIT50W" (from MsftEdit.dll) and not the "RichEdit20W" class (from 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;

enter image description here

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219