.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);更多推荐
发布评论