Board index » cppbuilder » DrawFocus Color

DrawFocus Color


2005-07-01 05:31:36 AM
cppbuilder48
Hi, I am doing this and it works, I see A tiny reddish focus rectangle,
but it does not work when I change the color to clBlack, what am I doing
wrong?: I just want to make the focus look on my TLabels.
Thanks
Simon
My Code:
TRect rect;
rect.Left = 2;
rect.Top = 2;
rect.Right = Label1->Width-2;
rect.Bottom = Label1->Height-2;
Label1->Canvas->Brush->Color = clBackground;
Label1->Canvas->DrawFocusRect(rect);
 
 

Re:DrawFocus Color

"Simon Guertin" < XXXX@XXXXX.COM >wrote in message
Quote
Hi, I am doing this and it works
Where exactly are you calling that code from? The only place you should be
doing any drawing on a control is from its virtual Paint() method, an
OnPaint event handler, or in response to the WM_PAINT message directly.
Quote
I see A tiny reddish focus rectangle, but it does not work when I
change the color to clBlack, what am I doing wrong?
You cannot set the color for the focus rectangle yourself. It is drawn by
using colors that are the XOR of the existing pixels on the drawing area.
If the control's background is clBlack, then clWhite pixels should appear
for the focus rectangle. If the background surrounding the rectangle's
pixels is also clWhite (or whitish or just very light), then you won't see
the drawn pixels because they merged with the surrounding colors.
Quote
I just want to make the focus look on my TLabels.
Why? A TLabel is not a windowed control, so it cannot receive input focus
to begin with. Drawing a focus rectangle on a control that cannot receive
focus is likely to confuse the user.
Gambit
 

Re:DrawFocus Color

I needed to create a new Component that looks and behave like the
TCheckBox but with the properties of the TLabel. I need the label to be
transparent and it is not supported in the Caption part of the TCheckbox.
That is why I need to dray the focus on the label.
And the code you provided me (about making a new component that is a
combination of 2 existing component ) is working fine for now
Simon
Remy Lebeau (TeamB) wrote:
Quote
"Simon Guertin" < XXXX@XXXXX.COM >wrote in message
news:42c4651f$ XXXX@XXXXX.COM ...


>Hi, I am doing this and it works


Where exactly are you calling that code from? The only place you should be
doing any drawing on a control is from its virtual Paint() method, an
OnPaint event handler, or in response to the WM_PAINT message directly.


>I see A tiny reddish focus rectangle, but it does not work when I
>change the color to clBlack, what am I doing wrong?


You cannot set the color for the focus rectangle yourself. It is drawn by
using colors that are the XOR of the existing pixels on the drawing area.
If the control's background is clBlack, then clWhite pixels should appear
for the focus rectangle. If the background surrounding the rectangle's
pixels is also clWhite (or whitish or just very light), then you won't see
the drawn pixels because they merged with the surrounding colors.


>I just want to make the focus look on my TLabels.


Why? A TLabel is not a windowed control, so it cannot receive input focus
to begin with. Drawing a focus rectangle on a control that cannot receive
focus is likely to confuse the user.


Gambit


 

{smallsort}

Re:DrawFocus Color

"Simon Guertin" < XXXX@XXXXX.COM >wrote in message
Quote
I needed to create a new Component that looks and behave
like the TCheckBox but with the properties of the TLabel.
We've already discussed this component earlier this week. Why did you start
a new discussion thread for it?
Quote
That is why I need to dray the focus on the label.
Derive a new component from TLabel instead of using TLabel itself. Then
your custom TLabel can draw its own focus rectable inside of its overriden
Paint() method when the owner TCheckBox currently has focus. The CheckBox
should not be drawing on the TLabel at all.
Gambit
 

Re:DrawFocus Color

Thank you, I am sorry about the new thread, I though that my DrawFocus
question was not relevant to the new component thread issue.
Simon
Remy Lebeau (TeamB) wrote:
Quote

We've already discussed this component earlier this week. Why did you start
a new discussion thread for it?


>That is why I need to dray the focus on the label.


Derive a new component from TLabel instead of using TLabel itself. Then
your custom TLabel can draw its own focus rectable inside of its overriden
Paint() method when the owner TCheckBox currently has focus. The CheckBox
should not be drawing on the TLabel at all.


Gambit