RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomRichEdit.DefAttributes Property

Describes the rich text characteristics of the default font for the rich edit control

Pascal
property DefAttributes: TTextAttributes;
C++
__property TTextAttributes DefAttributes;

Use DefAttributes to discover or set the default font characteristics that the rich edit control uses for newly inserted text. These are the characteristics of the text before any special attributes have been applied. Once any special attributes are applied to a portion of text, no text from that point on is considered to have the default attributes, even if the attributes match the DefAttributes. 

For example, if a rich edit control has had no attributes applied, the entire text has the default attributes. Selecting a portion of text in the middle and applying a specific attribute (such as a font change) results in three sections: a first section with the default attributes, a middle section with the applied attribute, and a final section with a non-default set of attributes that match the default attributes. Changing the DefAttributes property affects only the first section. 

When inserting new text, the font characteristics of the new text will match the font characteristics at the cursor position, or, if the typing replaces a selection, the font characteristics of the selected text. New text will only have the default attributes when typed into the section of text that has the default attributes.

Note: DefAttributes is available only at runtime.
 

C++ Examples: 

 

/*
This example requires a TRichEdit and two TButtons. Leave
the default text, usually "RichEdit1", in the lines
property. The DefAttributes will apply to this text.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  RichEdit1->SelAttributes->Color = clRed;
  RichEdit1->SelAttributes->Height += 5;
  RichEdit1->Lines->Add("This line of text will be red. ");
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  RichEdit1->DefAttributes->Color = clBlue;
  RichEdit1->DefAttributes->Style =
    RichEdit1->DefAttributes->Style << fsBold << fsItalic;
}

 

Delphi Examples: 

{
This example requires a TRichEdit and two TButtons. Leave
the default text, usually "RichEdit1", in the lines
property. The DefAttributes will apply to this text.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  with RichEdit1.SelAttributes do
  begin
    Color := clRed;
    Height := Height + 5;
  end;
  RichEdit1.Lines.Add('This line of text will be red.');
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
  RichEdit1.DefAttributes.Color := clBlue;
  RichEdit1.DefAttributes.Style := [fsBold, fsItalic];
end;

 

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