A Screenshot Software Using Visual C#

Introduction:

I wanted to learn how to make a screenshot application or screen capture application using Microsoft Visual C# 2008. So, I started searching online on how to make this. So far I have learnt how to take the screenshot of the whole screen. And I am going to share the source code with you.
Here is the screenshot of my product:


Source Code:


At first use the following namespaces at your file.

using System.Drawing.Imaging;
using System.IO;

Now add a button in your form. And add the following codes for the button click event.

private void button1_Click(object sender, EventArgs e)
{
    this.Hide();
    System.Threading.Thread.Sleep(250);

    int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
    int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
    Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
    Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
    gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));

    SaveFileDialog sfd = new SaveFileDialog();
    sfd.Filter = "PNG image | *.png| JPEG Image|*.jpg";
    sfd.Title = "Save The ScreenShot";
    sfd.ShowDialog();

    if(sfd.FileName != "")
    {
        FileStream fs = (FileStream)sfd.OpenFile();
        switch(sfd.FilterIndex)
        {
            case 1:
                bmpScreenShot.Save(fs, ImageFormat.Png);
                break;
            case 2:
                bmpScreenShot.Save(fs, ImageFormat.Jpeg);
                break;
        }
        fs.Close();
    }

    this.Show();
    this.Activate();

}

This application will now take a screenshot from your whole screen and then prompt you to save in PNG format or JPEG format.

Thank you all.

0 comments :

Post a Comment

Spam comments will be deleted. :)

 
Loading...
TOP