0

I use tRichEdit to set line colors. I want to decrease line space like tMemo.

When I input an alphabet manually the line space decreases automatically but when I use tRichEdit.lines.add nothing happens.

If it's not possible are there any substitutes?

enter image description here

JO SeongGng
  • 567
  • 3
  • 18
  • I can't reproduce this. By "input manually", do you mean typing at the keyboard? I just did a quick test app, and I get no difference between adding them via `RichEdit1.Lines.Add` and entering on the keyboard. – Ken White May 18 '15 at 19:47
  • 1
    Line spacing has nothing to do with how text is added, whether manually or with `Lines.Add()`. It is related to the font that you have assigned to the RichEdit, or you can use `EM_SETPARAFORMAT` to configure the spacing via the `PARAFORMAT2.dyLineSpacing` structure field. – Remy Lebeau May 18 '15 at 19:52
  • @KenWhite yes i typed. i guessed it was because of font or character set but they were same even after that. thanks. – JO SeongGng May 18 '15 at 21:15

1 Answers1

7

You can adjust line spacing by sending the EM_SETPARAFORMAT via SendMessage, setting PFM_LINESPACING in the dwMask and providing values for the dyLineSpacing value (and setting the bLineSpacingRule value so that the RichEdit knows how to interpret the former). The code below sets a very tight linespacing in the TRichEdit (the lines actually slightly overlap each other):

procedure TForm1.FormCreate(Sender: TObject);
var
  Para: TParaFormat2;
begin
  Para.cbSize := SizeOf(Para);
  Para.dwMask := PFM_LINESPACING;
  Para.bLineSpacingRule := 4;  // Use exact twips specified
  Para.dyLineSpacing := 120;   // Ridiculously small value
  SendMessage(RichEdit1.Handle, EM_SETPARAFORMAT, 0, LPARAM(@Para));
end;

For more information, see the MSDN documentation for EM_SETPARAFORMAT

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • i appreciate your kind answer and delicate code. it works well and is helpful. – JO SeongGng May 18 '15 at 21:38
  • thank you so much, I found that in WinWord and WordPad you can get line spacing less than 1 (single line) also with rule 5, RichEdit only with rule 4 – MtwStark Oct 03 '17 at 13:10