Hi
Today I was playing around with some window form and came up with a simple and interesting requirement. I wanted to take a print screen of the monitor from inside the application. What I wanted to do was allow the user to save the screen as and when they wanted it from inside the application.
So first thing I had to do for this was to find out the resolution of the screen that the user was working with. Because the screenshot need to be save of the same size as the screen resolution. This can be done by using the System.Windows.Forms.SystemInformation class. This class provides a static method PrimaryMonitorSize which gives us the monitor size. This property is of type Size. So we have width and height of the screen using the following code.
int width, height;
width = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width;
height = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Height;
The following code will capture the screen and save it in the desktop as image.bmp;
Bitmap sBit;
Rectangle screenRegiion = Screen.AllScreens[0].Bounds;
sBit = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics sGraph = Graphics.FromImage(sBit);
sGraph.CopyFromScreen(screenRegiion.Left, screenRegiion.Top, 0, 0, screenRegiion.Size);
string savedPath =Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\VikramLakhotia.bmp";
sBit.Save(savedPath);
Thanks
Vikram