.NET Winform

编程入门 行业动态 更新时间:2024-10-28 14:29:30
.NET Winform - usercontrol的缩略图(.NET Winform - thumbnail of usercontrol)

我有一个使用一些用户控件的应用程序。 我想在用户控件加载后使用它们的缩略图,并将它们添加到流程布局面板中。

我在哪里可以找到关于在加载时制作usercontrol的缩略图的信息?

I have an app which uses some usercontrols. I want to take a thumbnail image of the usercontrols when they are loaded for use and add them to a flowlayout panel.

Where can I find information on making a thumbnail image of a usercontrol when it's loaded?

最满意答案

我不知道有什么方法可以在显示之前完成它,但是一旦它显示在屏幕上,您可以使用类似这样的方法:

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);

I don't know of a way to do it before it has been displayed, but once it is on the screen you could use an approach like this:

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

You can use it to get a thumbnail of any control, like this:

myPictureBox.Image = GetControlThumb(someControl, 100);

更多推荐

本文发布于:2023-07-22 14:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1220574.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   Winform

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!