我有使用了一些用户控件的应用程序。我想,当它们被加载用于采取用户控件的缩略图像,并将它们添加到一个的FlowLayout面板。

我在哪里可以找到,当它装做一个用户控件的缩略图信息?

有帮助吗?

解决方案

我不知道的方式做到这一点已经显示之前,但一旦它出现在屏幕上,你可以使用这样的方法:

private Image GetControlThumb(Control control, int thumbSize)
{
    Bitmap imgLarge = new Bitmap(control.Bounds.Width, control.Bounds.Height);
    using (Graphics g = Graphics.FromImage(imgLarge))
    {
        g.CopyFromScreen(
            control.Parent.PointToScreen(new Point(control.Left, control.Top)),
            new Point(0, 0),
            new Size(control.Bounds.Width, control.Bounds.Height));
    }


    Size size;
    if (control.Width > control.Height)
    {
        size = new Size(thumbSize, (int)(thumbSize * (float)control.Height / (float)control.Width));
    }
    else
    {
        size = new Size((int)(thumbSize * (float)control.Width / (float)control.Height), thumbSize);
    }
    Image imgSmall = imgLarge.GetThumbnailImage(size.Width, size.Height, new Image.GetThumbnailImageAbort(delegate { return false; }), IntPtr.Zero);
    imgLarge.Dispose();
    return imgSmall;

}

您可以用它来得到任何控制的缩略图,这样的:

myPictureBox.Image = GetControlThumb(someControl, 100);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top