【发布时间】:2014-04-01 13:04:44
【问题描述】:
我希望我的控件在拖动时显示在屏幕上。
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
}
}
这就是我所拥有的,我有一个FlowLayoutPanel,您可以在其中拖放一些面板控件,在我的 foreach 语句中,我希望每个控件都转换为位图图像,所以在拖动时,在DragEnter事件,我可以显示控件截图。我想我做得对,首先定义了一个Bitmap 图像列表,然后制作了一个带有控件宽度和高度的新位图,然后我将该位图添加到我的controlsImgs 列表中。现在在我的 for 循环中,我必须在屏幕上绘制每个控件图像。怎么做 ?该控件的位置与鼠标位置相同,即e 位置。
【问题讨论】:
标签: c# winforms bitmap drag-and-drop