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.
And this is the code for the Picture 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
__________________________________________________ _______________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:
Basically means "The code for Options Form" and "Close coding for options form".Code:Public Class Options End Class
_____________________
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 Options_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label3.Text = "ScreenShot" Label4.Text = "0" End Sub
_____________________
Ok now this is a little more complicated.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
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:
Just means "Code for Picture Form" and "Stop code for Picture Form".Code:Public Class Picture End Class
___________________
When Form1 Loads (Picture.vb / Picture Form), Make the window state maximized). Stop coding for Picture.Load.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 you click the Picture Form, Hide the form.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 PictureBox1, Hide the form.Code:Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click Hide() End Sub
__________________________________________________ _______________
Thankyou for reading this tutorial.
Made by Travy92,
Special thanks to TcM for giving me the idea
Attachments for my ScreenShot Program are below:
Last edited by Jordan; 04-11-2008 at 09:42 AM.
this is good
Hey! I typed it up in Visual Basic and:
7 ERRORS.
How'd ya know? didtca ask someone?
Yeah I know. I'm using VS2008 (Visual Studio 2008 right?). Wait a minute... ARGH! I FORGOT IT'S IN 2.0 Mode last time! (forgot to exchange it.)
Uh, at 9 (or was it 10?) ?
Hey wait a minute. Aren't we off the topic?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks