Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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);

}

Posted

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);

  • 1 year later...
Posted

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

Wanna-Be C# Superstar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...