julz barrab

julz barrab

  • NA
  • 26
  • 0

Array of Draggable Labels/objects (im half way ther) - help plz

Jul 24 2007 6:23 AM
Hi,

I have managed to (on button click) create a label and get the label to be dragged and droped around the screen. But i need to have multiple labels on screen that can be individually dragged around, can any1 help me out with the code i would need for this, as i'm fairly new to C#, so my brain hasnt managed to figure this one out yet,

Thanks in advance :)

Julian
-------------------------

Here a summary of my current code...

// creating a label
lblDragger = new System.Windows.Forms.Label()

// drag and drop event handlers
lblDragger.MouseUp += new MouseEventHandler(this.lblDragger_MouseUp);
lblDragger.MouseMove += new MouseEventHandler(this.lblDragger_MouseMove);
lblDragger.MouseDown += new MouseEventHandler(this.lblDragger_MouseDown);


// the dragging and dropping

private void lblDragger_MouseDown(Object sender, MouseEventArgs e)
{
isDragging = true;
clickOffsetX = e.X;
clickOffsetY = e.Y;
}

private void lblDragger_MouseUp(Object sender, MouseEventArgs e)
{
isDragging = false;
this.groupBox1.Controls.Add(this.lblDragger);
}

private void lblDragger_MouseMove(Object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (isDragging == true)
{
lblDragger.Left = e.X + lblDragger.Left - clickOffsetX;
lblDragger.Top = e.Y + lblDragger.Top - clickOffsetY;
}
Invalidate();
}


Answers (7)