RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDBRichEdit.WordWrap Property

Determines whether the edit control inserts soft carriage returns so text wraps at the right margin.

Pascal
property WordWrap: Boolean;
C++
__property Boolean WordWrap;

Set WordWrap to true to make the edit control wrap text at the right margin so it fits in the client area. The wrapping is cosmetic only. The text does not include any return characters that were not explicitly entered. Set WordWrap to false to have the edit control show a separate line only where return characters were explicitly entered into the text.

Note: There should be no use for a horizontal scroll bar if WordWrap is true.
 

C++ Examples: 

 

/*
This example requires: TRichEdit, TRadioGroup, TCheckBox, 
TButton. Clicking the Radio Group control sets the ScrollBar
style of the RichEdit. Toggling the Check Box turns 
HideScrollBars on and off.  Clicking the button loads the 
Rich Edit with a large amount of contiguous text.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  RichEdit1->Lines->Clear();
  for (int i = 0; i < 500; i++)
  {
    RichEdit1->Text = RichEdit1->Text + AnsiString("This is sentence ") + IntToStr(i) + ".  ";
    if ((i % 2) == 0) {
      RichEdit1->Text = RichEdit1->Text + AnsiString("\n");
    }
  }
  RichEdit1->SelStart = 0; // move text cursor to top of edit
}

void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
  RichEdit1->HideScrollBars = CheckBox1->Checked;
}

void __fastcall TForm1::RadioGroup1Click(TObject *Sender)
{
  TScrollStyle ScrollBarA[4] = {ssBoth, ssHorizontal, ssNone, ssVertical };
  RichEdit1->ScrollBars = ScrollBarA[RadioGroup1->ItemIndex];
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  RadioGroup1->Caption = "Scroll Bars";
  RadioGroup1->Items->Clear();
  RadioGroup1->Items->Add("ssBoth");
  RadioGroup1->Items->Add("ssHorizontal");
  RadioGroup1->Items->Add("ssNone");
  RadioGroup1->Items->Add("ssVertical");
  CheckBox1->Caption = "Hide Scroll Bars";
  CheckBox1->Checked = true;
  Button1->Caption = "Load Text";
  RichEdit1->Text = "Just a little text.";
  RichEdit1->WordWrap = False;
}

 

Delphi Examples: 

{
This example requires: TRichEdit, TRadioGroup, TCheckBox, 
TButton. Clicking the Radio Group control sets the ScrollBar
style of the RichEdit. Toggling the Check Box turns 
HideScrollBars on and off.  Clicking the button loads the 
Rich Edit with a large amount of contiguous text.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  RichEdit1.Lines.Clear;
  for I := 0 to 500 do
  begin
    RichEdit1.Text :=
      RichEdit1.Text + 'test line ' + IntToStr(I) + ' ';
    if (i mod 4 = 0) then
      RichEdit1.Text := RichEdit1.Text + Chr(13);
  end;
  // move text cursor to top of editend;
  RichEdit1.SelStart := 0; 
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  RichEdit1.HideScrollbars := CheckBox1.Checked;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
const
  ScrollBarA: array[0..3] of TScrollStyle = (
    ssBoth,
    ssHorizontal,
    ssNone,
    ssVertical);
begin
  RichEdit1.ScrollBars := 
    ScrollBarA[RadioGroup1.ItemIndex];
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with RadioGroup1, Items do
  begin
    Caption := 'Scroll Bars';
    Clear;
    Add('ssBoth');
    Add('ssHorizontal');
    Add('ssNone');
    Add('ssVertical');
  end;
  with CheckBox1 do
  begin
    Caption := 'HideScrollBars';
    Checked := True;
  end;
  Button1.Caption := 'Loaded';
  RichEdit1.Text := 'Just a little text.';
  RichEdit1.WordWrap := False;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!