Sam_Sorrow Posted December 11, 2003 Posted December 11, 2003 I have a previously selfcreated user-control which contains a picturebox and some additional code, also included is a method that changes the displayed Image in the Picturebox on Clicking. This works fine so far. Now I place this user control on a new form and i want it to fire a Click-Event on my form when a user clicks it. The Image in the Pictuebox changes on clicking but the Eventhandler on my form doesnt fire anything on clicking! I need a possibility for the users of my user control to write their own code for a click-event on that control. I read about the possibility to bubble events from a user control to its parent control but it was related to web forms. Is it equivalent to Windows forms? If it is, how does it work because i dont get to the point yet... Thanks in advance for your help, Jan Quote
HJB417 Posted December 11, 2003 Posted December 11, 2003 what I would do is, make an event in the class of the selfcreated user-control called PictureBoxClicked, then add a private method called OnPictureBoxClicked(object sender, EventArgs e), and add OnPictureBoxClicked(this, EventArgs.Empty) to the last line of whatever code handles the OnClick event in the selfcreated user-control. OnPictureBoxClicked would look like this OnPictureBoxClicked(object sender, EventArgs e) { PictureBoxClicked(sender, e); } Quote
Sam_Sorrow Posted December 11, 2003 Author Posted December 11, 2003 Dont understand that proposal I cannot follow your proposal. How can I catch the Click event within my parent form that contains the user control? Quote
HJB417 Posted December 11, 2003 Posted December 11, 2003 The parent form would need to listen to the event. inside your parent form, you would need to do something like selfCreatableUserControl myControl = new selfCreatableUserControl(); //tell the control what method(s) you want invoked after the control's picture box has been clicked and the image has changed selfCreatableUserControl.PictureBoxClicked += new EventHandler(UserControlPictureClicked); Quote
Sam_Sorrow Posted December 11, 2003 Author Posted December 11, 2003 still confused Many thanks so far, but how do I add an event to my user control class? I think to do this a need a delegate to? still confused, jan Quote
Sam_Sorrow Posted December 11, 2003 Author Posted December 11, 2003 Success Yes, now my code is working! Thank you very much for your help! Jan Quote
VBAHole22 Posted December 10, 2005 Posted December 10, 2005 Could you post the code that you got to work? I'm trying to get this done 2.0 style and I'm having difficulty registering the event on the aspx page because of the partial class business Quote Wanna-Be C# Superstar
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.