在屏幕上绘制位图 [英] Drawing bitmap on screen

查看:263
本文介绍了在屏幕上绘制位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的控制拖动时显示在屏幕上。

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
    }
}

下面是我有什么,我有一个 FlowLayoutPanel的,在这里你可以拖放一些控件这是面板,在我的foreach语句我想每个控制转换成位图图像,所以拖动时,在的dragenter 事件,我可以显示控制屏幕截图。我觉得我做得正确,首先定义和位图的列表图像,然后做了一个新的位图与对照宽高,那我也补充说,位图到我的 controlsImgs 列表。现在在我的for循环我要在屏幕上绘制的每个控制图像。怎么做 ?该控件的位置是一样的鼠标位置,意味着电子位置。

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.

推荐答案

使用的 Control.DrawToBitmap 。 (见一个例子 href=\"http://stackoverflow.com/a/10180168/939213\">。)

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

要设置新的光标使用 GiveFeedback在事件。这样做:

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

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

这篇关于在屏幕上绘制位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆