By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,172 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,172 IT Pros & Developers. It's quick & easy.

Event handlers from components

P: n/a
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

Nov 3 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Mon, 03 Nov 2008 07:19:01 -0800, greg <th*****@nospam.nospamwrote:
[...]
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
Nov 3 '08 #2

P: n/a
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" wrote:
On Mon, 03 Nov 2008 07:19:01 -0800, greg <th*****@nospam.nospamwrote:
[...]
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
Nov 3 '08 #3

P: n/a
On Mon, 03 Nov 2008 11:03:00 -0800, greg <th*****@nospam.nospamwrote:
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?
Well, your container _is_ the parent.

It seems to me that, since it's the MouseClick event you're interested in,
what you want to do is handle the MouseClick event in the child controls,
and then call OnMouseClick() in the parent control. You'll need to
translate the mouse coordinates in the MouseEventArgs, passing a new
instance of that to the OnMouseClick() method so that the MouseClick event
that's raised is correct. The easiest way to do that is translate from
client to screen for the child control, then back to client coordinates
for the container.

Pete
Nov 3 '08 #4

P: n/a
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 (v-****@online.microsoft.com, 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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#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/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 5 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.