我有一个使用一些用户控件的应用程序 . 我想在加载用户控件时获取用户控件的缩略图,并将它们添加到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);
1 回答
我不知道在显示之前有办法做到这一点,但是一旦它出现在屏幕上你可以使用这样的方法:
您可以使用它来获取任何控件的缩略图,如下所示: