Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named btn_customer to my form, my wish is to add new small picturebox to the coordinates that the user click on the pic_map and the new added picturebox should have click event to get the location of it when it is clicked and also be a member of the picturebox array.
after clicking the btn_customer, the coordinate thet user click on the pic_map there should be added a new picturebox with a tag number increasing 1 every time.
i have written some code in C# but when clicking one of the small picturebox it just gets the location of the last added one, not the one that i clicked on .
here is my code:
- pic_map: main picturebox
-
-
i global int, initial value=0
-
-
musteri=new Bitmap("f:musteri_button.jpg");
-
PictureBox [] node; //global
-
-
private void pic_map_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
-
{
-
x=e.X;
-
y=e.Y;
-
node=new PictureBox[50];
-
if((e.Button==MouseButtons.Left)&&(tag==1))
-
{
-
i=i+1;
-
node[j]=new PictureBox();
-
node[j].Image=musteri;
-
node[i].Size=new System.Drawing.Size(36,26);
-
node[i].Location=new System.Drawing.Point(x,y);
-
node[i].Visible=true;
-
node[i].Name="node"+i;
-
node[i].Click += new System.EventHandler(this.node_Click);
-
node[i].Tag=i;
-
this.pic_map.Controls.Add(node[i]);
-
}
-
private void btn_customer_Click(object sender, System.EventArgs e)
-
{
-
tag=1;
-
}
-
-
private void node_Click(object sender, EventArgs e)
-
{
-
int a,b;
-
a=node[Convert.ToUInt32(((PictureBox)sender).Tag)].Location.X;
-
b=node[Convert.ToUInt32(((PictureBox)sender).Tag)].Location.Y;
-
}
Please help me, thanks for your consider....