Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: [VCL] Color of TStaticText


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: May 13, 2017 10:45 AM Last Post By: Gabriel GRIPARI Threads: [ Previous | Next ]
Gabriel GRIPARI

Posts: 24
Registered: 3/26/09
[VCL] Color of TStaticText  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 6, 2017 12:31 AM
Hello,

I'm workging with C++ Builder Enterprise Tokyo.
I would like to create dynamicaly a TStaticText. I wrote :

TFont *MyFont = new TFont() ;
MyFont->Color = clRed;
MyFont->Name = "Verdana";
MyFont->Size = 8;

TStaticText *StaticText1 = new TStaticText(this);
StaticText1->Visible = false;
StaticText1->Parent = Form1;
StaticText1->ParentFont = false;
StaticText1->Top = 100;
StaticText1->Left = 200;
StaticText1->Font = MyFont;
StaticText1->Caption = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StaticText1->Visible = true;

StaticText1 is properly setted with the correct font, mais the color is black instead of red.
How can i set the color of the font in red ?

Best regards

Gabriel
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: [VCL] Color of TStaticText  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 6, 2017 7:44 AM   in response to: Gabriel GRIPARI in response to: Gabriel GRIPARI
Hi GRIPARI

This will make the font read, but the background will also be non transparent,
so I suggest you use TLabel instead of TStaticText

   TStaticText *StaticText1 = new TStaticText(this);
   StaticText1->Visible = false;
   StaticText1->Parent = Form1;
   StaticText1->ParentFont = false;
   StaticText1->ParentColor = false;
   StaticText1->Top = 300;
   StaticText1->Left = 200;
   StaticText1->Transparent = false;
   StaticText1->Caption = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   StaticText1->Font->Color = clRed;
   StaticText1->StyleElements = StaticText1->StyleElements >> seClient >> seFont;
   StaticText1->Visible = true;


Best regards
Asger
Gabriel GRIPARI

Posts: 24
Registered: 3/26/09
Re: [VCL] Color of TStaticText  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 7, 2017 3:05 AM   in response to: Asger Joergensen in response to: Asger Joergensen
Hello,

Thanks, for your response.
Could you help me one more time ?

I don't know any possibility to click on an TLabel and sending the event to the parent window the TLabel.
Is it possible ?

Best regards

Gabriel
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: [VCL] Color of TStaticText  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 7, 2017 4:02 AM   in response to: Gabriel GRIPARI in response to: Gabriel GRIPARI
Hi GRIPARI

GRIPARI Gabriel wrote:

Hello,

Thanks, for your response.
Could you help me one more time ?

I don't know any possibility to click on an TLabel and sending the event to the parent window the TLabel.
Is it possible ?

I don't understand what you want, in the VCL all events are just functions
assigned to function pointers, so you can select any TNotifyEvent from the
OnClick dropdown in the Object Inspectors event tab.

You can even assign events from other forms, if you do it in code:

Label1->OnClick = &FormClick;

Label1->OnClick = &Form2->FormClick;

You might find these tutorials useful:
https://www.youtube.com/user/vclexamples/videos

Best regards
Asger
Sebastian Ledesma

Posts: 78
Registered: 11/9/00
Re: [VCL] Color of TStaticText  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 7, 2017 8:42 AM   in response to: Gabriel GRIPARI in response to: Gabriel GRIPARI
GRIPARI Gabriel wrote:
Hello,

I'm workging with C++ Builder Enterprise Tokyo.
I would like to create dynamicaly a TStaticText. I wrote :
...
StaticText1 is properly setted with the correct font, mais the color is black instead of red.
How can i set the color of the font in red ?

If the application uses Windows Themes then you need to dissable the theme for the static control that you want to define the color.

Sebas
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: [VCL] Color of TStaticText  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 8, 2017 12:19 PM   in response to: Gabriel GRIPARI in response to: Gabriel GRIPARI
GRIPARI wrote:

TFont *MyFont = new TFont() ;

Make sure you 'delete' that object after you assign it to StaticText1->Font,
otherwise it will be leaked. Otherwise, don't create a TFont object at all,
just use the one that TStaticText already provides:

StaticText1->Font->Color = clRed;
StaticText1->Font->Name  = "Verdana";
StaticText1->Font->Size  = 8;


Either way, you don't need to set ParentFont=false manually, changing the
Font property does that automatically for you.

StaticText1 is properly setted with the correct font, mais the color
is black instead of red. How can i set the color of the font in red ?

Unlike TLabel, TStaticText is a windowed control (it is a wrapper for a Win32
STATIC control). If your app has Win32 Runtime Themes or VCL Styles enabled,
the coloring will be taken from the current theme/style, ignoring any color
you assign.

--
Remy Lebeau (TeamB)
Gabriel GRIPARI

Posts: 24
Registered: 3/26/09
Re: [VCL] Color of TStaticText  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 13, 2017 10:45 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks for Asger, Sebastian, and Remy
I really appreciate the help you give me

Gabriel
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02