Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#3

Re: Tabulatorpositionen im RichEdit

  Alt 29. Apr 2008, 19:59
Hallo,

Vielleicht macht der Code von den Newsgroups das was du möchtest.

Zitat von P. Below:
Tab positions are a paragraph property in this control, so you use the Paragraph.Tab property to set tabstop positions. At least that is the theory.
Unfortunately the Tab property has been plagued by a longstanding bug, so you are better off setting tabstops by using the EM_SETPARAFORMAT message. Here is an example, add the
Richedit unit to your uses clause for the message and TParaformat type.


Delphi-Quellcode:
{-- SetTabstops -------------------------------------------------------} 
{: Set tabstops at the indicated positions in the current paragraph
@Param re is the richedit control to modify
@Param TabPositions is an array of positions to set. The unit used
  are inches and the array needs to be sorted.
@Precondition  re <> nil
@Desc Note: if the TabPositions array contains more than MAX_TAB_STOPS
  entries the extras will not be used.


}
{ Created 2004-04-15 by P. Below


-----------------------------------------------------------------------}
 
procedure SetTabstops( re: TRichedit; TabPositions: array of single );
Var
  pf: TParaFormat;
  i : Integer;
  charwidth : Integer;
begin
  Assert( Assigned( re ), 'SetTabstops: re cannot be nil' );
  FillChar( pf, sizeof(pf), 0);
  pf.cbSize := Sizeof( pf );
  pf.dwmask := PFM_TABSTOPS;
  if High(TabPositions) >= MAX_TAB_STOPS then
    pf.cTabCount := MAX_TAB_STOPS
  else
    pf.cTabCount := High(TabPositions)+1;
  For i:= 0 To pf.cTabCount-1 Do
    pf.rgxTabs[i] := Trunc(TabPositions[i] * 1440);

  re.perform( EM_SETPARAFORMAT, 0, Integer( @pf ));
end; { SetTabstops } 


procedure TForm1.Button1Click(Sender: TObject);
begin
  with RichEdit1 do
  begin
    Clear;
    SelStart := GetTextLen; // position caret at end
    SelAttributes.Style := [];
    SelAttributes.Color := clBlack;
    SetTabstops( richedit1, [0.5, 1.0, 1.5, 2.5] );
    SelText := 'STRING1'+#9+'STRING2'+#9+'STRING3'+#13#10+
      'A'#9'B'#9'C'#9'D'#9'E';
  end;
end;
Thomas
  Mit Zitat antworten Zitat