473,406 Members | 2,369 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,406 software developers and data experts.

User control Click Event handling

I build user control, consists of different things (e.g label, image, etc.)
I want to handle click (and other) events, however I can not do it until I
do not assign event handler for each control inside me user contol. Is there
way to do this "smart" just inherit all possible events from usercontrol
class instead of rewriting custom handlers for each control inside ???

Thankx
Nov 15 '05 #1
2 29041
you mean you dont want to write event handler for label
control in side your control, however if some one clicks
on label you should get the click event out of your
control ...

Till some one tells you the real solution, i have a
suggestion to reduce little bit of your pain, write a
macro to write the event handler for your controls,
because all the controls click event can call your one
click event so there is hardly any change in the code
from one control to other controls click event ...

public delegate void MyClick (object
sender, System.EventArgs e);
public event MyClick cClick ;

private void UserControl1_Click(object
sender, System.EventArgs e)
{
if (cClick != null)
cClick (sender,e);
}

private void label1_Click(object sender,
System.EventArgs e)
{
UserControl1_Click( sender, e);
}

private void label2_Click(object sender, System.EventArgs
e)
{
UserControl1_Click( sender, e);
}

Let me know if i should go into how to write a macro
which will take your control name and expand it in to a
click event hadler function ..

Sarosh
-----Original Message-----
I build user control, consists of different things (e.g label, image, etc.)I want to handle click (and other) events, however I can not do it until Ido not assign event handler for each control inside me user contol. Is thereway to do this "smart" just inherit all possible events from usercontrolclass instead of rewriting custom handlers for each control inside ???
Thankx
.

Nov 15 '05 #2
Here's a concept I've used before. Since you don't say how you're
showing your image, I'm using PictureBox in the example, but it can be
adapted to any control.

this.label1.Click += new System.EventHandler(this.PassThrough_Click);
this.pictureBox1.Click += new System.EventHandler(this.PassThrough_Click);
// etc.

// Click of label and picture box are sent to control
private void PassThrough_Click(object sender, System.EventArgs e)
{
this.OnClick( e );
}

Chris R.

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:e$*************@tk2msftngp13.phx.gbl...
I build user control, consists of different things (e.g label, image, etc.) I want to handle click (and other) events, however I can not do it until I
do not assign event handler for each control inside me user contol. Is there way to do this "smart" just inherit all possible events from usercontrol
class instead of rewriting custom handlers for each control inside ???

Thankx

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
5
by: George Durzi | last post by:
I have a simple user control with a text box and a submit button. When the user enters some text into the textbox and clicks the submit button, a record is created in the database. I'm using...
9
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
5
by: Paul Bromley | last post by:
For some time now I have been struggling trying to understand how to handle events originating in a User Control that I have designed when using this in an application. Basically I need to respond...
3
by: c676228 | last post by:
Hi all, I have an event in user control email to handling email change when user want to change the input for email address. Here it is In email.ascx.vb: Protected Sub UpdateEmail(ByVal sender As...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
3
by: Toty Santana | last post by:
I need to make a new user control; it will contain a button and a drop down list. Can I make the button click event handling editable by the user, like he can specify the method that will handle...
2
by: RSH | last post by:
Hi, I have been trying to follow a tutorial on raising an event from a user control and then handling it in the parent page. The article is a little vague so I believe I have the code in...
1
by: Efi Merdler | last post by:
Hi, I created a user control, but instead of handling exception in the user control level I prefer to handle them in the containing form. In the load event of the containing form I'm using:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.