Board index » cppbuilder » Unable to change default font in TRichEdit

Unable to change default font in TRichEdit

I have a form and a TRichEdit whose font is set to CourierNew at
design time. I need to capture user preferences at startup time, and
change the default font accordingly. My attempt at this (which does
not work) is illustrated below.

{ // in form constructor

  RichEdit1->DefAttributes->Name = "System";  // for example

Quote
}

{ // in OnFormShow event
  RichEdit1->SelectAll();    //  in case RE already has some text
  RichEdit1->SelAttributes = RichEdit1->DefAttributes; // set to default
  RichEdit1->SelStart = 0;
  RichEdit1->SelLength = 0;

Quote
}

The above does not work; when I start assigning lines to RichEdit1,
they are still in 9-point Courier New.  Can anyone please say what
I'm doing wrong here?

Thanks,
Adrian Carter

 

Re:Unable to change default font in TRichEdit


Quote
"Adrian Carter" <Adria...@bigpond.com> wrote in message

news:3ea2aea0@newsgroups.borland.com...

Quote
>   RichEdit1->SelectAll();    //  in case RE already has some text
>   RichEdit1->SelAttributes = RichEdit1->DefAttributes; // set to default
>   RichEdit1->SelStart = 0;
>   RichEdit1->SelLength = 0;

All you've managed to do with that code is set the font attributes for that
particular section of selected text, not for the entire RichEdit in general.

For what you ask for, you'll need to set the SelStart property to the *end*
of the RichEdit text so that you're setting the font attributes from that
edit position onward, so that new text from that point on will have the
assigned attributes.  for example:

    if( RichEdit->GetTextLen() > 0 )
    {
        RichEdit1->SelectAll();
        RichEdit1->SelAttributes = RichEdit1->DefAttributes;
        RichEdit1->SelStart = RichEdit1->SelLength;
        RichEdit1->SelLength = 0;
        RichEdit1->SelAttributes = RichEdit1->DefAttributes;
    }

Gambit

Re:Unable to change default font in TRichEdit


"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3ea3196d$1@newsgroups.borland.com...

Quote

> All you've managed to do with that code is set the font attributes for
that
> particular section of selected text, not for the entire RichEdit in
general.

> For what you ask for, you'll need to set the SelStart property to the
*end*
> of the RichEdit text so that you're setting the font attributes from that
> edit position onward, so that new text from that point on will have the
> assigned attributes.  for example:

>     if( RichEdit->GetTextLen() > 0 )
>     {
>         RichEdit1->SelectAll();
>         RichEdit1->SelAttributes = RichEdit1->DefAttributes;
>         RichEdit1->SelStart = RichEdit1->SelLength;
>         RichEdit1->SelLength = 0;
>         RichEdit1->SelAttributes = RichEdit1->DefAttributes;
>     }

> Gambit

Thanks Gambit, this works ok when I put it in a simple test project, but
does not work in my real project. I think I have got some other issues to
work through with this - possibly to do with an OnSelectionChange event.
I'll post a followup if I can't suss it out.

Adrian Carter

Other Threads