View Single Post
  #1 (permalink)  
Old 04-10-2008, 07:59 PM
travy92's Avatar   
travy92 travy92 is offline
Learning Programmer
 
Join Date: Sep 2007
Location: Australia
Age: 15
Posts: 71
Rep Power: 4
travy92 is on a distinguished road
Send a message via MSN to travy92
Post VB2008 Tutorial - Print Screen

Hello everyone! I recently saw TcM's code of Print Screen and i decided to try and make it to see if i could do what he could do .

So i ended up with a full code (not advanced as TcM's though, he's a much more experienced programmer).

__________________________________________________ _______________

GUI
Options Form:



Picture Form:

__________________________________________________ _______________

What you will need:

2 Forms named:

Options.vb (Form1)
Picture.vb (Form2)



On the options form:

4 Labels named:


Name: Label1
Text: "ScreenShot Name:"

Name: Label2
Text: "ScreenShot No."

Name: Label3
Text: "Label3"

Name: Label4
Text: "Label4"


1 Command Button named:
Name: Button1
Text: "Take ScreenShot"


On the Picture Form you will need:

1 PictureBox named:
Name: PictureBox1
__________________________________________________ _______________

Ok now for the code:
This is the full Code, the explanation follows:


This is the code for the Options Form.

Code:
Public Class Options

    Private Sub Options_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label3.Text = "ScreenShot"
        Label4.Text = "0"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Hide()
        Label3.Text = "ScreenShot"
        Label4.Text = Format(Val(Label4.Text) + 1)
        Threading.Thread.Sleep(2000)
        SendKeys.Send("{Prtsc}")
        Threading.Thread.Sleep(1000)
        Picture.Show()
        Picture.PictureBox1.Image = My.Computer.Clipboard.GetImage
        Try
            Picture.PictureBox1.Image.Save("ScreenShot " & Label4.Text & ".bmp")
        Catch
            MsgBox("ERROR! There is already a file named ScreenShot " & Label4.Text & ".", MsgBoxStyle.OkOnly & MsgBoxStyle.Critical, "ERROR!")
        End Try
        Show()
        Threading.Thread.Sleep(1000)
        Activate()
    End Sub
End Class
And this is the code for the Picture Form.

Code:
Public Class Picture

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
    End Sub

    Private Sub Picture_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        Hide()
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Hide()
    End Sub
End Class
__________________________________________________ _______________

CODE EXPLANATION

For the Options Form:

Code:
Public Class Options
End Class
Basically means "The code for Options Form" and "Close coding for options form".
_____________________

Code:
Private Sub Options_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label3.Text = "ScreenShot"
        Label4.Text = "0"
    End Sub
When the form loads (Options Form), Label3's text becomes "ScreenShot" and Label4's text becomes "0". Then Ends the Options_load event.

_____________________

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Hide()
        Label3.Text = "ScreenShot"
        Label4.Text = Format(Val(Label4.Text) + 1)
        Threading.Thread.Sleep(2000)
        SendKeys.Send("{Prtsc}")
        Threading.Thread.Sleep(1000)
        Picture.Show()
        Picture.PictureBox1.Image = My.Computer.Clipboard.GetImage
        Try
            Picture.PictureBox1.Image.Save("ScreenShot " & Label4.Text & ".bmp")
        Catch
            MsgBox("ERROR! There is already a file named ScreenShot " & Label4.Text & ".", MsgBoxStyle.OkOnly & MsgBoxStyle.Critical, "ERROR!")
        End Try
        Show()
        Threading.Thread.Sleep(1000)
        Activate()
    End Sub
Ok now this is a little more complicated.
When you click the Button1 Button, the following events are fired (in order of the code above):

- Hides Form
- Changes Label3's text to "ScreenShot"
- Changes Label4's text to + 1 of what it already is (eg. If Label4's text is 4 then it becomes 5)
- Make Thread Sleep (Pause for 2 sec)
- Send the keys (Prtsc) which is Print Screen
- Makes Thread Sleep (Pause for 1 sec)
- Show the Picture Form
- Get the Image that you jsut ScreenShotted
- Try to save the image with the name, but if there's already a file with the same name, do the following:
- Provides a message box telling you that there is another file with the same name
- Stops Try
- Shows the main form (Options.vb)
- Make Thread Sleep (Pause for 1 sec)
- Activate Options.vb (Options Form)
- End Codes for Button1

________________________________________

Picture Form Code:

Code:
Public Class Picture
End Class
Just means "Code for Picture Form" and "Stop code for Picture Form".

___________________

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
    End Sub
When Form1 Loads (Picture.vb / Picture Form), Make the window state maximized). Stop coding for Picture.Load.

___________________

Code:
Private Sub Picture_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        Hide()
    End Sub
When you click the Picture Form, Hide the form.

___________________

Code:
Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Hide()
    End Sub
When you click PictureBox1, Hide the form.

__________________________________________________ _______________

Thankyou for reading this tutorial.

Made by Travy92,
Special thanks to TcM for giving me the idea

Attachments for my ScreenShot Program are below:
Attached Files To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
__________________
Quote:
The pacifist's task today is to find a method of helping and healing which provides a revolutionary constructive substitute for war.

Last edited by Jordan; 04-11-2008 at 11:42 AM.
Reply With Quote

Sponsored Links