Last active
December 17, 2015 20:59
-
-
Save afrael/5671353 to your computer and use it in GitHub Desktop.
Grabs the content of a Windows Control and returns its bitmap image -- especially useful for long running operations where you might want to "dim" the control a put a spinner on top of it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
GrabControlBitmapImage | |
Created on 2013/05/28 by Afrael Ortiz | |
Grabs the content of a Windows Control and returns its bitmap image | |
-- "do whatever you want with this" license -- | |
*/ | |
public static Bitmap GrabControlBitmapImage(Control control) | |
{ | |
var controlBounds = control.Bounds; | |
using (var bitmap = new Bitmap(controlBounds.Width, controlBounds.Height)) | |
{ | |
using (var g = Graphics.FromImage(bitmap)) | |
{ | |
var controlLocation = control.PointToScreen(Point.Empty); | |
g.CopyFromScreen(controlLocation, Point.Empty, controlBounds.Size); | |
} | |
return new Bitmap(bitmap); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment