473,385 Members | 1,764 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,385 software developers and data experts.

User control events

Hey guys
I have created a user control to be a custom button.

When the control is on the form the event 'Click' doesn't do anything.

The contol is just a standard label on the control form. And I want to use
the click event for the label not the underlying form/control background
(whatever it is).

The click event for the background is whats being fired when clicked.
Any ideas???
Cheers in advance
May 5 '06 #1
2 5847
"Steve" <sg*******@clear.net.nz> wrote in message
news:44******@clear.net.nz...
Hey guys
I have created a user control to be a custom button.

When the control is on the form the event 'Click' doesn't do anything.

The contol is just a standard label on the control form. And I want to
use the click event for the label not the underlying form/control
background (whatever it is).

The click event for the background is whats being fired when clicked.
Any ideas???


You need to grab the click event for the label (within the usercontrol) and
re-raise that event.

[DefaultEvent("Click")]
public class XCont : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Label label1;

public new event EventHandler Click;

public XCont()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 72);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// XCont
//
this.Controls.Add(this.label1);
this.Name = "XCont";
this.ResumeLayout(false);

}

private void label1_Click(object sender, System.EventArgs e)
{
if(this.Click != null) Click(this, EventArgs.Empty);
}
}
May 5 '06 #2
cheers dude - worked a treat
"Michael C" <no****@nospam.com> wrote in message
news:uA*************@TK2MSFTNGP05.phx.gbl...
"Steve" <sg*******@clear.net.nz> wrote in message
news:44******@clear.net.nz...
Hey guys
I have created a user control to be a custom button.

When the control is on the form the event 'Click' doesn't do anything.

The contol is just a standard label on the control form. And I want to
use the click event for the label not the underlying form/control
background (whatever it is).

The click event for the background is whats being fired when clicked.
Any ideas???


You need to grab the click event for the label (within the usercontrol)
and re-raise that event.

[DefaultEvent("Click")]
public class XCont : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Label label1;

public new event EventHandler Click;

public XCont()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 72);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// XCont
//
this.Controls.Add(this.label1);
this.Name = "XCont";
this.ResumeLayout(false);

}

private void label1_Click(object sender, System.EventArgs e)
{
if(this.Click != null) Click(this, EventArgs.Empty);
}
}

May 5 '06 #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...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
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...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
4
by: thomson | last post by:
Hi all, i do have a user control with 4 buttons, and all the events are firing properly, My problem is that i need to right an event handler in the user control, which gets fired after a...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
6
by: Art | last post by:
Hi I'm new at this and need some help. I have a "solution" with 2 projects - the main project and a library. The library is simple, it contains a text box that will appear many times in the form...
1
by: Israel | last post by:
The problem: I want to know, definitively when a slider loses focus after a user has started sliding and hasn't released the mouse yet. It appears that this is captured with the WM_ACTIVATEAPP...
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...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.