ScreenShot Maker [Well Explained Tutorial - C#]

All tutorials created in C# to be posted in here.
7 posts Page 1 of 1
Contributors
User avatar
Code
VIP - Donator
VIP - Donator
Posts: 51
Joined: Sun Sep 18, 2011 7:25 pm

Create a new Windows From Application.
Add:
3 buttons
1 Picture Box
Details: Follow this tutorial and you won't be confused!
Double click on your form and put this code above everything.
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
This is just your simple dim's(I am use too VB.net so thats what i know them as)
Insert this under the public form1()
Code: Select all
        {
            InitializeComponent();
        }
        private static Bitmap bmpScreenshot;
        private static Graphics gfxScreenshot;
Double click your form and insert this code for your capture button.
This basically means that when your going to take a screenshot for the application to hide first then take the screenshot as a bmp then show the application. This way we do not have the physical application in the picture.
Button1: Capture
Code: Select all
{
            this.Hide();
            System.Threading.Thread.Sleep(1000);
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
            gfxScreenshot = Graphics.FromImage(bmpScreenshot);
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
            pictureBox1.Image = bmpScreenshot;
            System.Threading.Thread.Sleep(1000);
            this.Show();
        }
Now you may use a button, toolstrip button or anything for this.
This is basically your clear button. If you do not like the picture you just took this will clear your picture box.
Button2: Clear
Code: Select all
{
            pictureBox1.Image = null;
        }
This is how we will save your screenshot, this code tells the program too open a save window where you can chose where you want to save your image.
Button3: Save
Code: Select all
{
            saveFileDialog1.FileName = "";
            saveFileDialog1.ShowDialog();
            try
            {
                pictureBox1.Image.Save(saveFileDialog1.FileName);
                System.Diagnostics.Process.Start(saveFileDialog1.FileName);
                saveFileDialog1.FileName = "";
            }
            catch
            {
            }
        }
I hope this tutorial made sense and was helpful as this was my first C# tutorial!
If you see any errors or mistakes please point them out!
Last edited by Code on Sun Sep 25, 2011 6:18 pm, edited 1 time in total.
viewtopic.php?f=17&p=54101#p54101
Image
Image
Image
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

You cant convert a string "" to a image. It will be an error at the clear code
Code: Select all
{
      pictureBox1.Image = "";
}
Last edited by MrAksel on Sun Sep 25, 2011 11:27 am, edited 1 time in total.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

I think an empty string represents null(vbNull) but I don't know
http://vagex.com/?ref=25000
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

i don't know about c# but in vb.net you can do
Code: Select all
picturebox1.image = nothing
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Code: Select all
picturebox1.Image = null;
works fine
Top-notch casual Dating
User avatar
Zulf
Serious Programmer
Serious Programmer
Posts: 441
Joined: Fri Jun 11, 2010 7:46 am

Agust1337 wrote:
Code: Select all
picturebox1.Image = null;
works fine
Or
Code: Select all
pictureBox1.Clear();
Image
User avatar
Code
VIP - Donator
VIP - Donator
Posts: 51
Joined: Sun Sep 18, 2011 7:25 pm

Sorry, i was not home. Just got back, i fixed up the code. Thanks for the help!
viewtopic.php?f=17&p=54101#p54101
Image
Image
Image
7 posts Page 1 of 1
Return to “C-Sharp Tutorials”