Board index » delphi » RichEdit & TABs

RichEdit & TABs

Hallo,

how can I set the positions for TABs in generell? I mean they should be
active when a new richedit is opened or when an open richedit is filled with
text via LoadFromFile.

I tried it with paragraph.tab but it doesn't do what I want.

Thank you for your help.

Dietmar

 

Re:RichEdit & TABs


Quote
In article <3bf50b66_2@dnews>, Dietmar Mysliwietz wrote:
> how can I set the positions for TABs in generell? I mean they should be
> active when a new richedit is opened or when an open richedit is filled with
> text via LoadFromFile.

> I tried it with paragraph.tab but it doesn't do what I want.

The property is somewhat screwed up, best use the API way directly:
The positions need to be specified in twips (1/1440 inch) for the
EM_SETPARAFORMAT message.

The following method sets tabstops every 5 average character positions, based
on the current paragraphs font.

procedure TForm1.Button2Click(Sender: TObject);
Const
  tabs : Array [0..5] of Integer = (5,10,15,20,25,30);
  teststring = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
Var
  pf: TParaFormat;
  i : Integer;
  charwidth : Integer;
begin
  FillChar( pf, sizeof(pf), 0);
  pf.cbSize := Sizeof( pf );
  pf.dwmask := PFM_TABSTOPS;
  pf.cTabCount := 6;
  Canvas.Font.Assign( richedit1.SelAttributes );
  charwidth := (Canvas.TextWidth( teststring ) * 1440)
               div
               (Screen.PixelsPerInch * Length(teststring));
               // average charwidth in twips
  For i:= 0 To High( tabs ) Do
    pf.rgxTabs[i] := tabs[i] * charwidth;

  If richedit1.perform( EM_SETPARAFORMAT, 0, Integer( @pf )) = 0
  Then ShowMessage('Failed');
end;

Add the Richedit unit to your Uses clause. If you do this setting on an empty
richedit control it will become the default for new text entered. If you read
in formatted text you would have to do a selectAll, then set the tabstops,
to make them effective for the loaded text.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads