Re: Click Event of a Dynamically added object
From: Bruce Wood (brucewood_at_canada.com)
Date: 11/15/04
- Next message: Phil Jones: "Re: Asking a TreeNode if it's CheckBox is visible."
- Previous message: Herfried K. Wagner [MVP]: "Re: Can you find a MenuItem by name?"
- In reply to: Bob: "Click Event of a Dynamically added object"
- Next in thread: Bob: "Re: Click Event of a Dynamically added object"
- Reply: Bob: "Re: Click Event of a Dynamically added object"
- Messages sorted by: [ date ] [ thread ]
Date: 15 Nov 2004 13:56:59 -0800
Bob <Bob@discussions.microsoft.com> wrote in message news:<1ECF8809-EF77-4C5D-84D4-6E88C02C8476@microsoft.com>...
> I have an Image object that is dynamically created in a tabcontrol 1 or many
> times. The Image is a custom class that has many mouse functions. I have
> trapped the LeftMouseDown and call an overrideable function called SelectMe()
> withine the Custom Image class. Ok here is where I am unsure. I need to
> be able to click on any of the one to many Images and bring that Image up in
> a Larger Edit area. My problem is that don't know the best way to be able to
> get that Click back to the Form Level so I can bring the image and its custom
> properties up in the larger Image area which is dynamically created at the
> form level. Is my concept correct? if so how do I override the SelectME()
> function at the form level? I assume it is somehere around where I add the
> Object to the TabPageControls(). Both the 1 or many images and the Edit
> Image are based on the same Custom Image Object I created. Ideas would be
> much appreciated. I am working in VB .Net
I just finished doing exactly this, but in C#, not VB. My VB is
terrible, so I'll advise you in prose rather than in code.
Your concept is rougly correct. As you add each Image object to the
container, you must register a method in the container to handle the
Click event of the Image. So, you have a Click event handler in your
Form class, and for every Image you add to the tab control (or
wherever), you say something like:
newImage.Click += new System.EventHandler(this.Image_Click);
where this.Image_Click is a method in your Form class. Yes, I know
that's C# (sorry), but I hope that you get the idea.
Inside the Image_Click method you'll receive one argument that is the
object that sent the event. This will be the Image that was clicked.
So, now the Image_Click method just has to do whatever it wants to do
when an image is clicked, since it has a reference to the clicked
Image passed to it.
So, to sum up:
o Write a method in your Form that responds to the Click event, but
don't hook it up to anything on your form. Just give it the correct
return type and arguments for the kind of method that handles a Click
event. Let's call the method Image_Click().
o When you create a new Image and add it to your tab control, add your
form's Image_Click method as a listener to the Click event of the
image.
o In the Image_Click method, the "sender" object will be the Image
that was clicked. Just cast it from an object to an Image, and do
whatever needs to be done.
o Image_Click will be called whenever any image is clicked.
- Next message: Phil Jones: "Re: Asking a TreeNode if it's CheckBox is visible."
- Previous message: Herfried K. Wagner [MVP]: "Re: Can you find a MenuItem by name?"
- In reply to: Bob: "Click Event of a Dynamically added object"
- Next in thread: Bob: "Re: Click Event of a Dynamically added object"
- Reply: Bob: "Re: Click Event of a Dynamically added object"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|