0

I want my controls to show on screen when dragging.

private void flowLayoutPanel1_DragEnter(object sender, DragEventArgs e)
{
    FlowLayoutPanel _destination = (FlowLayoutPanel)sender;
    e.Effect = _destination.Controls.GetChildIndex(_destination.GetChildAtPoint(_destination.PointToClient(new Point(e.X, e.Y)))) >= 0 ? DragDropEffects.Move : DragDropEffects.None;


    foreach (Control control in flowLayoutPanel1.Controls)
    {
        List <Bitmap> controlsImgs = new List<Bitmap>();
        Rectangle controlsRect = new Rectangle(e.X,e.Y,control.Width,control.Height);
        Bitmap b = new Bitmap(control.Width, control.Height);
        control.DrawToBitmap(b, new Rectangle(0, 0, b.Width, b.Height));
        controlsImgs.Add(b);

    }

    for (int i = 0; i < controlsImgs.Count; i++)
    {
        //TODO
    }
}

Here is what I have, I have a FlowLayoutPanel, where you can drag and drop some controls which are panels, in my foreach statement I want each control to convert into bitmap image, so when dragging, in DragEnter event, I can show the controls screenshot. I think I done correctly, first have defined a list of Bitmap images, then made a new bitmap with the controls width and height, then I have added that bitmap to my controlsImgs list. Now in my for loop I have to draw each controls image on the screen. How to do that ? That control's position is the same as the mouse position, means the e position.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Romo Daneghyan
  • 2,099
  • 3
  • 18
  • 23

1 Answers1

0

Use Control.DrawToBitmap . (See an example here.)

To set the new cursor use the GiveFeedback event. Do:

e.UseDefaultCursors = false;
Cursor.Current = MyCursor;
Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291