PDA

Click to See Complete Forum and Search --> : [RESOLVED] user control


popskie
Jan 18th, 2006, 10:18 PM
hi,
I created my own user control it composed of button,label and a picturebox the problem is how to add an on click event in my control?

private usercontrolname pb1 = new usercontrolname ();
pb1.Click += new System.EventHandler(ako);

I have already this one in my code but when I click the button the event wasn't fired. the event occur when i click outside the button in my user control.

pls. help me.

Popskie

RohanWest
Jan 19th, 2006, 02:56 AM
You have implemented the Click Method for the control, not the OnClick event for the Button.

You can either... Expose the button by making a property that encapsulates the button used on your form, you will be able to add the event like this..

private usercontrolname pb1 = new usercontrolname ();
pb1.MyButton.Click += new System.EventHandler(ako);

or you could add your own event that gets fired when the user clicks the button.

Rohan

popskie
Jan 19th, 2006, 03:13 AM
so i need to declare the properties of button modifier as public. Am i correct?

RohanWest
Jan 19th, 2006, 03:37 AM
You can do that

or make a property like this

public Button MyButton
{
get{return buttonOnForm;}
}

popskie
Jan 19th, 2006, 04:04 AM
it work great!!!
thank u very much Rohan.