1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[C#] Screen Shot App

Discussion in 'C, C++, C#' started by cyberbrute, Aug 4, 2013.

  1. cyberbrute

    cyberbrute Registered Member

    Joined:
    Jul 29, 2013
    Messages:
    72
    Likes Received:
    47
    Occupation:
    Student
    Location:
    Pakistan
    This is a simple app to make screenshots:

    make a Win Form then add controls accordingly.

    then add following code:

    Code:
    using System.Drawing.Imaging;using System.Threading;
    
    
    ///////////////// Declarations ////////////////////////
    ImageFormat img; Bitmap bt; Graphics screenShot;
    
    
    ///////////////////// Button1 /////////////////////////////
    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    {
        this.Hide();
        // This gives time to the Form to hide before it takes the screenshot. 500 miliseconds are enough.
        Thread.Sleep(500); 
        // Set the image to the size of the screen.
        bt = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
        // Creates the graphic object for the image (bt).    
        screenShot = Graphics.FromImage(bt);
        // Takes the screenshot.
        screenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, 
    
    
    CopyPixelOperation.SourceCopy);
        switch (saveFileDialog1.FilterIndex)
        {
            case 0: img = ImageFormat.Bmp; break;
            case 1: img = ImageFormat.Png; break;
            case 2: img = ImageFormat.Jpeg; break;
        }
        // Saves the image.
        bt.Save(saveFileDialog1.FileName, img);
        // After the screenshot is taken the Form reappears.
        this.Show();
    }
    if you need any help please let me know.

    Cheers
     
  2. mftiuri

    mftiuri Newbie

    Joined:
    Feb 21, 2010
    Messages:
    16
    Likes Received:
    0
    And what if I need to take a screen shot of a video? :p Your little program won't work.