Jump to content
Xtreme .Net Talk

Sending click events from a custom control back to the form the control is on


Recommended Posts

Posted
I have this user control I made called a Blob. The blob is a small control that has a panel on it, covering the entire control, and a label on the top half of the panel. And I have a Form with a number of Blobs on them. I�ve managed to get the Blob, each of them, to respond to a click on the panel (the part that isn�t covered by the label) by popping up a message box that identifies the Blob � by putting a message box in the Panel�s Mouse_Down handler (the message box displays a property of the Blob called �longname� � each Blob has a different one). However, I don�t know how to pass the longname (or some other id) back to the form that the Blob is on. I don't even know how to get the form to realize that a Blob has been clicked on, in addition to which blob it was. Putting something in the MouseDown handler of the form itself only reacted when I clicked on a part of the form that was not covered by a Blob. Thanks in advance.
Posted

This may not be the best solution but you could pass the form class by ref in the constructor of blob and assign it to a global variable. This way whatever you do to the global variable will happen to the form.

 

PB

Posted

attach a method of your form to all of your blobs click/mouse down event.

 

when the method is fired the blob will be the sender argument

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

Thanks for your help. How do I go about attaching a method of the form to all the blobs? I mean considering that the Blobs are created at run time. The code I have that adds new Blobs when necessary looks like this:

 

Dim newblob As Blob = New Blob

...several properties of newblob are set..

 

Me.Controls.Add(newblob)

 

Do I need to add something to attatch the method on the form to the newbob? Thanks again in advance :)

 

 

attach a method of your form to all of your blobs click/mouse down event.

 

when the method is fired the blob will be the sender argument

Posted

How about something like

 

public class Form1 : System.Windows.Forms.Form
{
 private System.Windows.Forms.MainMenu mainMenu1;
 private System.Windows.Forms.MenuItem menuItem1;

 etc etc...

 public void DoSomething (string something) 
 { 
   ..... 
 }

 public void CreateBlobs ()
 {
   BLOB b = new BLOB(ref this);
 }
}

public class BLOB
{
 private Form1 useform;
 public BLOB (ref Form1 form)
 {
    useform = form;
 }

 public void DosomethingtoForm ()
 {
    useform.DoSomthing("Hello from BLOB");
 }
}

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...