BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to make a Control with other controls within respond to

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
wh
Guest





PostPosted: Fri Jun 24, 2005 2:23 pm    Post subject: how to make a Control with other controls within respond to Reply with quote



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





PostPosted: Fri Jun 24, 2005 8:31 pm    Post subject: Re: how to make a Control with other controls within respond Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.