我希望我的控件在拖动时显示在屏幕上。
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
位置。
使用Control.DrawToBitmap。(在此处查看示例。)
要设置新光标,请使用GiveFeedback事件。做:
e.UseDefaultCursors = false;
Cursor.Current = MyCursor;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句