 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
RGreen Guest
|
Posted: Tue Jun 07, 2005 11:47 am Post subject: TCustom panel descendent and child graphic controls |
|
|
Hello all!
I have created a panel from a TCustomPanel. I have overrided the Paint
method with my own. The panel is painted fine. The only problem is the
following:
If I place some graphic component on my panel (a Tlabel, Timage, etc), when
I click on my panel, those components disapear. I must the cover the panel
with some control to for a repaint and then the children components are
shown again. This doesn't happen with a TWindowsControl descendent(Tedit,
etc).
I'm sure I am missing something here, but what?
Regards
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jun 07, 2005 5:12 pm Post subject: Re: TCustom panel descendent and child graphic controls |
|
|
"RGreen" <RGreen (AT) nospam (DOT) org> wrote
| Quote: | This doesn't happen with a TWindowsControl descendent(Tedit, etc).
|
TCustomPanel is a TWinControl descendant.
| Quote: | I'm sure I am missing something here, but what?
|
Please show your actual code.
Gambit
|
|
| Back to top |
|
 |
RGreen Guest
|
Posted: Tue Jun 07, 2005 7:05 pm Post subject: Re: TCustom panel descendent and child graphic controls |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
TCustomPanel is a TWinControl descendant.
|
Yes, I know. And the point is....? I mean, if I place a TEdit on my panel,
everything works OK, but placing a TLabel or any other TgraphicControl
descendant shows this weird behavior.
| Quote: | I'm sure I am missing something here, but what?
My paint prcedure (overriden) : |
procedure TExPanel.Paint();
var
CFace: TColor;
CText: TColor;
CBorder: TColor;
Dx, Dy, x, y: integer;
rect: Trect;
begin
if Enabled then
begin
CFace := FColorFace;
CText := FColorCaption;
CBorder := FColorBorder;
end
else
begin
CFace := $00E9E9E9;
CText := clGray;
CBorder := clSilver;
end;
Canvas.Brush.Color := CFace;
Canvas.Pen.Color := CBorder;
Canvas.Pen.Width := 1;
{if not FFlat then
begin
Canvas.Rectangle(2, 2, ClientWidth - 2, ClientHeight - 2);
Canvas.Pen.Color := clBtnHighlight;
Canvas.Pen.Width := 2;
Canvas.MoveTo(0, 0);
Canvas.LineTo(ClientWidth - 1, 0);
Canvas.MoveTo(0, 0);
Canvas.LineTo(0, ClientHeight - 1);
Canvas.Pen.Color := clBtnShadow;
Canvas.MoveTo(ClientWidth - 1, 0);
Canvas.LineTo(ClientWidth - 1, ClientHeight-1);
Canvas.MoveTo(0, ClientHeight - 1);
Canvas.LineTo(ClientWidth - 1, ClientHeight - 1);
end else }
Canvas.Rectangle(0, 0, ClientWidth, ClientHeight);
if Trim(Caption) = '' then
Exit;
x := 0;
y := 0;
Canvas.Brush.Style := bsClear;
Canvas.Pen.Color := CText;
Canvas.Font := Font;
Canvas.Font.Color := CText;
Dx := Canvas.TextWidth(Caption);
Dy := Canvas.TextHeight(Caption);
case FCaptionAlign of
cpCenter:
begin
x := (ClientWidth div 2) - (Dx div 2);
y := (ClientHeight div 2) - (Dy div 2);
end;
cpTop:
begin
x := (ClientWidth div 2) - (Dx div 2);
y := 5;
end;
cpBottom:
begin
x := (ClientWidth div 2) - (Dx div 2);
y := ClientHeight - Dy - 5;
end;
cpLeft:
begin
x := 5;
y := (ClientHeight div 2) - (Dy div 2);
end;
cpRight:
begin
x := ClientWidth - Dx - 5;
y := (ClientHeight div 2) - (Dy div 2);
end;
cpLeftTop:
begin
x := 5;
y := 5;
end;
cpLeftBottom:
begin
x := 5;
y := ClientHeight - Dy - 5;
end;
cpRightTop:
begin
x := ClientWidth - Dx - 5;
y := 5;
end;
cpRightButtom:
begin
x := ClientWidth - Dx - 5;
y := ClientHeight - Dy - 5;
end;
end; //case
Rect.Left:=x-1;
Rect.Top:= y-1;
Rect.Right:=Rect.Left+ Dx+ 1;
Rect.Bottom:= Rect.Top + Dy +1;
//Canvas.TextOut(x, y, Caption);
DrawText(Canvas.Handle,
PChar(Caption),
length(Caption),
Rect,
DT_CENTER or DT_VCENTER or DT_SINGLELINE or DT_NOCLIP);
end;
Nothing strange here
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jun 07, 2005 7:19 pm Post subject: Re: TCustom panel descendent and child graphic controls |
|
|
"RGreen" <RGreen (AT) nospam (DOT) org> wrote
| Quote: | Yes, I know. And the point is....?
|
Ignore it. I misread your earlier message.
| Quote: | My paint prcedure (overriden) :
|
You said that the problem occurs when you click on the Panel. Do you have
code that handles mouse clicks? Drawing the Panel itself should not have
any effect on the visibility of its child controls.
Gambit
|
|
| Back to top |
|
 |
RGreen Guest
|
Posted: Tue Jun 07, 2005 8:15 pm Post subject: Re: TCustom panel descendent and child graphic controls |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
You said that the problem occurs when you click on the Panel. Do you have
code that handles mouse clicks? Drawing the Panel itself should not have
any effect on the visibility of its child controls.
|
Well, that's the problem. I had placed some
procedure TExPanel.Click;
begin
if not Enabled then
Exit;
FColorBorder := RGB(34,78,34);
Paint;
inherited;
end;
in my OnClick event, because I wanted to modify the color of the borders
when clicking. Commentng out the paint solved the problem. I now send a
message to repaint the panel.
Thank you for your help!
Regards
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jun 07, 2005 8:32 pm Post subject: Re: TCustom panel descendent and child graphic controls |
|
|
"RGreen" <RGreen (AT) nospam (DOT) org> wrote
| Quote: | procedure TExPanel.Click;
|
That code is wrong. You should not be calling Paint() directly. Call
Invalidate() instead so that the component calls Paint() for you when it is
actually ready to be drawn. For example:
procedure TExPanel.Click;
begin
if Enabled then
begin
FColorBorder := RGB(34,78,34);
Invalidate; // <-- HERE
inherited;
end;
end;
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|