Setting User Control click event runtime

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I want to create a customized button, so Ive created a User Control with a PictureBox inside it and added various events (MouseEnter etc.) to animate it. This works very well, but I cant get the Click event to work. I want to be able to decide what the
click event does in my program, at runtime, like this:
<pre class="prettyprint public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

myUserControl.Click += new EventHandler(myUserControl_Click);
}

private void myUserControl_Click(object sender, EventArgs e)
{
//I want to be able to set the actions here.
}
}[/code]
The "animations" of the User Control are working properly, but the Click event in the code above is never triggered. If I add a Click event in the User Control, that will work, but I want to be able to set the event actions in the program, at runtime.
Anyone care to help me with this one?
Thanks!
-J

View the full article
 
Back
Top