 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
wh Guest
|
Posted: Fri Jun 24, 2005 2:23 pm Post subject: how to make a Control with other controls within respond to |
|
|
I have the following control based on a TCustomPanel with other controls
(TShape and TLabel) in it. The MouseDown (and all mouse events) only
respond to clicks on the basic "Panel" area. If I click over the TShape or
TLabel part of the control, my code is not invoked.
How can I make the control respond to all clicks within its area?
Thanks.
class PACKAGE TWPushButton : public TCustomPanel
{
private:
TShape *BtnShape ;
TLabel *BtnLabel ;
.....
protected:
void __fastcall WndProc( TMessage& Message ) ;
....
DYNAMIC void __fastcall MouseDown( TMouseButton Button,
Classes::TShiftState
Shift, int X, int Y ) ;
DYNAMIC void __fastcall MouseUp( TMouseButton Button,
Classes::TShiftState
Shift, int X, int Y );
public:
__fastcall TWPushButton(TComponent* Owner);
__published:
__property OnClick ;
__property OnMouseDown ;
__property OnMouseUp ;
.....
__fastcall TWPushButton::TWPushButton(TComponent* Owner)
: TCustomPanel(Owner)
{
BtnShape = new TShape( NULL ) ;
BtnLabel = new TLabel( NULL ) ;
BtnShape->Parent = this ;
BtnLabel->Parent = this ;
.....
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Fri Jun 24, 2005 8:31 pm Post subject: Re: how to make a Control with other controls within respond |
|
|
"wh" <w@h> wrote:
| Quote: |
[...] If I click over the TShape or TLabel part of the
control, my code is not invoked.
|
That is by design so you have to work around it. Simply define
2 events - ChildMouseDown and ChildMouseUp - and assign them
to the 2 objects. Then code it to look like:
void __fastcall TMySomething::ChildMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( FOnMouseDown )
{
// change x,y from child relative to parent relative
FOnMouseDown( Button, Shift, NewX, NewY );
}
}
For the OnClick event, in the ChildMouseUp, you just check if
the mouse is within the BoundsRect of the Parent object and if
it is, call the FOnClick if it is assigned.
~ JD
|
|
| 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
|
|