hello frds
I want to drag and drop all label created crossponding to checklist box's checked item.
But problem is only move last created label. other give no responce.
help me..
my code is.
public CheckedListBox chk;
private void Form1_Load(object sender, EventArgs e)
{
chk = new CheckedListBox();
chk.CheckOnClick = true;
chk.Items.Add("A");
chk.Items.Add("B");
chk.Items.Add("C");
chk.Items.Add("D");
chk.Items.Add("E");
chk.Items.Add("F");
}
static string stri;
public Label image;
int zx = 20;
int zy = 20;
Array arr;
private void button1_Click(object sender, EventArgs e)
{
label2.Text = "";
foreach (string str in chk.CheckedItems)
{
stri = str;
label2.Text += stri+",";
}
arr = label2.Text.Split(',');
for (int i = 0; i < arr.Length-1; i++)
{
image = new Label();
image.Text = arr.GetValue(i).ToString();
image.BackColor = Color.Aqua;
image.Location = new System.Drawing.Point(zx, zy);
this.Controls.Add(image);
zx = zx + 20;
zy = zy + 30;
if (arr.GetValue(i).ToString() == image.Text)
{
this.image.MouseUp += new MouseEventHandler(image_MouseUp);
this.image.MouseMove += new MouseEventHandler(image_MouseMove);
this.image.MouseDown += new MouseEventHandler(image_MouseDown);
}
else
{
MessageBox.Show("Selected Item is Not valid");
}
}
}
private bool isDragging1 = false;
private int clickOffsetX1, clickOffsetY1;
void image_MouseDown(object sender, MouseEventArgs e)
{
isDragging1 = true;
clickOffsetX1 = e.X;
clickOffsetY1 = e.Y;
}
void image_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging1 == true)
{
image.Left = e.X + image.Left - clickOffsetX1;
image.Top = e.Y + image.Top - clickOffsetY1;
}
}
void image_MouseUp(object sender, MouseEventArgs e)
{
isDragging1 = false;
}
I hope you will give me good solution