+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: VB2008 Tutorial - Print Screen

  1. #1
    travy92's Avatar
    travy92 is offline Learning Programmer
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    76
    Rep Power
    17

    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 Attached Files
    Last edited by Jordan; 04-11-2008 at 09:42 AM.
    C:\Users\Travis\Desktop\Image Converter\Knight1.bmp

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB2008 Tutorial - Print Screen

    Nice one, travy.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  4. #3
    kridan is offline Newbie
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Re: VB2008 Tutorial - Print Screen

    this is good

  5. #4
    Martin_kp's Avatar
    Martin_kp is offline Learning Programmer
    Join Date
    May 2008
    Location
    Indonesia
    Posts
    60
    Rep Power
    0

    Re: VB2008 Tutorial - Print Screen

    Hey! I typed it up in Visual Basic and:
    7 ERRORS.

  6. #5
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB2008 Tutorial - Print Screen

    Don't type it - grab it straight from the ZIP file. Are you using VS2008?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  7. #6
    Martin_kp's Avatar
    Martin_kp is offline Learning Programmer
    Join Date
    May 2008
    Location
    Indonesia
    Posts
    60
    Rep Power
    0

    Re: VB2008 Tutorial - Print Screen

    How'd ya know? didtca ask someone?

  8. #7
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB2008 Tutorial - Print Screen

    Er, no. This tutorial is about VS2008, so I'm confirming you're using the .NET Framework v3.5. If not, the objects are slightly different.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  9. #8
    Martin_kp's Avatar
    Martin_kp is offline Learning Programmer
    Join Date
    May 2008
    Location
    Indonesia
    Posts
    60
    Rep Power
    0

    Re: VB2008 Tutorial - Print Screen

    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.)

  10. #9
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB2008 Tutorial - Print Screen

    So - you're obviously quite young (like me) - you're into programming? When did you start learning?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  11. #10
    Martin_kp's Avatar
    Martin_kp is offline Learning Programmer
    Join Date
    May 2008
    Location
    Indonesia
    Posts
    60
    Rep Power
    0

    Re: VB2008 Tutorial - Print Screen

    Uh, at 9 (or was it 10?) ?
    Hey wait a minute. Aren't we off the topic?

+ Reply to Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Screen Print Program
    By sol49 in forum General Programming
    Replies: 1
    Last Post: 10-23-2011, 04:55 PM
  2. Intermediate [VB2008] Stopwatch Tutorial
    By CuzImAwesome in forum Visual Basic Tutorials
    Replies: 1
    Last Post: 10-20-2010, 08:02 PM
  3. print to screen without msg box ,help pls
    By romanbodenmiller in forum Visual Basic Programming
    Replies: 6
    Last Post: 12-10-2008, 10:56 AM
  4. print screen power
    By powerenergy in forum Software Development Tools
    Replies: 3
    Last Post: 04-24-2008, 02:06 PM
  5. Code: Print Screen v2
    By TcM in forum Visual Basic Tutorials
    Replies: 5
    Last Post: 09-26-2007, 05:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts