Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i have an arraylist containing a nu 1

Status
Not open for further replies.

seanbo

Programmer
Jun 6, 2003
407
GB
i have an arraylist containing a number of 'NodeInfo' objects. node info is made up of some primatives, and a windows component i designed called 'PreviewBox'.

preview box extends PictureBox. it is a dragable and resizable item that displays certain information relative to my project.

main form > array list of node info > preview box

i want to put a method in the code for my main form, the class that my array list is found within, that is triggered by an event such as my preview box being clicked.

i already have such a method withid preview box, but i don't know how to extend it in main form for every object in an unknown amount of objects. how would i go abou this?
 
Very simple.
If you choose to write a code for an event raising, you usually double click on the event at the events list, then the editor adds an empty method like:
Code:
private void button1_Click(object sender, System.EventArgs e)
{
// here you write the action
}
If you look at the hidden code which it's headline is:
Code:
Windows Form Designer generated code
you will see the function:
Code:
private void InitializeComponent()
In this function you will see a row like this:
Code:
this.button1.Click += new System.EventHandler(this.button1_Click);
The only thing you need is to do it yourself!
I had a similar case where I used an unknown amount of PictureBox created in runtime.
I made this function:
Code:
private PictureBox InitPicture(PictureBox pic)
{
    pic = new PictureBox();
    pic.Click += new System.EventHandler(ClickPic);
    pic.MouseHover += new EventHandler(pic_MouseHover);
    return pic;
}
In the main code I had a PictureBox array.
I allocated a new size to the array, and in a for loop I wrote:
Code:
pictures[i] = InitPicture(pictures[i]);
So now every PictureBox created will have the behavior as I wrote for the events Click and MouseHover.

Hope it helped you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top