473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Event handlers from components

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
4 3021
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pekka Karjalainen | last post by:
Hi, this is my first posting here. I also have a question about etiquette. There's a html file associated with my question. I cannot host it indefinitely at the current location. I don't, however,...
5
by: Mark Overstreet | last post by:
I am writing an app that needs to contain an object model that allows it to be controlled similiar to something like Word. However, I am writing this in C# and all managed code. I know that I can...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
1
by: AMP | last post by:
Sorry for my inexpieriance but all the event handlers I've programmed were with visual components. I need to write a handler for the System.IO.Ports.SerialDataReceivedEventHandler I have a...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
3
by: kevinforbes | last post by:
Hi All, I'm a little rusty on my C# so any help would be much appreciated. ..net 2.0, C#, using a COM object with events I have a COM object (built in C++) that throws various telephony...
8
by: sankar.vikram | last post by:
Hi I am using a com component in my C# application. But i getting error while i tried to call multiple events from my application. I'm getting the error "Exception from HRESULT: 0x80040202" ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.