Drawing bitmap on screen

醉酒当歌 提交于 2019-12-11 20:38:37

问题


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.


回答1:


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

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

e.UseDefaultCursors = false;
Cursor.Current = MyCursor;


来源:https://stackoverflow.com/questions/22786776/drawing-bitmap-on-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!