Event handlers from components

G

greg

Hi. I'm trying to implement a function.

Users are able to control-click on components. This turns the component red,
and does multi-selection and does some copying/pasting.

I'm having problems with some of my custom components. I've added the event
handler for MouseClick that simply pops up a message box for now to do some
debugging.

On Windows components, I can click no problem and it's triggered.

My custom component, which has a label and a text box -
- Clicking on the textbox, even is not triggered (this is okay by me
actually! :) )
- Clicking on the label itself, the event is not triggered.
- Click on any space *around* the label invokes the event.

Is there some sort of event passthrough I need to enable on my component?

Otherwise, all I can think of is adding the event at run-time :

myComponent.innerLabel.MouseDown += .. myHandler;

Thanks,
Greg
 
G

greg

Thanks Pete.

So, what sort of code would be in my custom component? I'm guessing I will
add a MouseDown event handler on my label, and then in that method, somehow
reraise the event so the parent can handle it?


Peter Duniho said:
[...]
My custom component, which has a label and a text box -
- Clicking on the textbox, even is not triggered (this is okay by me
actually! :) )
- Clicking on the label itself, the event is not triggered.
- Click on any space *around* the label invokes the event.

Is there some sort of event passthrough I need to enable on my component?

Sort of. Child controls get first chance at user input events, and if
they handle them, the parent container won't see them. You need to handle
the event in the child controls, and then re-raise them from the container.

It's hard to know for sure, since you didn't post a concise-but-complete
code example demonstrating your problem. But I suspect that's what you're
seeing.

Pete
 
J

\Ji Zhou [MSFT]\

Hello Greg,

I agree with Peter's comments. Since the message routines from the child
control to our component. We have to register the InnerLabel's MouseClick
event to get notified when the clicking occurs on the label.

I will add some codes about this approach as follows,

public Form1()
{
InitializeComponent();
this.myComponent1.label1.MouseClick += new
MouseEventHandler(label1_MouseClick);
}

void label1_MouseClick(object sender, MouseEventArgs e)
{
myComponent1_MouseClick(sender, e);
}

void myComponent1_MouseClick(object sender, MouseEventArgs e)
{
MessageBox.Show("Component Clicked");
}

Please let me know if you need any future assistance on this problem. I
will try my best to follow up. Have a nice day, Greg!


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top