Jump to content

Screen Shot

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
VBnet

VBnet

    Newbie

  • Members
  • PipPip
  • 18 posts
Hello CodeCall Members!!

I will be showing you how to take a screen shot with VB.NET

First you´ll need 2 Buttons and a picture box wich covers a big area

place the first button and rename it to "Take Screenshot", then add the code :

Dim bounds As Rectangle

        Dim screenshot As System.Drawing.Bitmap

        Dim graph As Graphics

        bounds = Screen.PrimaryScreen.Bounds

        screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, 


System.Drawing.Imaging.PixelFormat.Format32bppArgb)

        graph = Graphics.FromImage(screenshot)

        graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)

        PictureBox1.Image = screenshot

then place the second button, name it "Save", then add the code :

Dim savefiledialog1 As New SaveFileDialog

        Try

            savefiledialog1.Title = "Save File"

            savefiledialog1.FileName = "*.jpeg"

            savefiledialog1.Filter = "JPEG |*.jpeg"

            If savefiledialog1.ShowDialog() = DialogResult.OK Then

                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)

            End If

        Catch ex As Exception 'Do Nothing

        End Try

and at last add the picture box, make sure it covers a big area so that the screenshot will fit in.

Edited by WingedPanther, 07 May 2009 - 02:58 AM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Not bad, but PLEASE be sure to use the code tags (the # button) when posting code, especially in a tutorial.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Look at these properties:

savefiledialog1.Title = "Save File"
            savefiledialog1.FileName = "*.jpeg"
            savefiledialog1.Filter = "JPEG |*.jpeg"

Why not simply add a dialog from the toolbox? It would save a lot of coding work.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#4
VBnet

VBnet

    Newbie

  • Members
  • PipPip
  • 18 posts

Xav said:

Look at these properties:

savefiledialog1.Title = "Save File"

            savefiledialog1.FileName = "*.jpeg"

            savefiledialog1.Filter = "JPEG |*.jpeg"


Why not simply add a dialog from the toolbox? It would save a lot of coding work.

hmm. dunno why.. i dont mind doing some code work.. :001_tt2:

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Lol - but if it's easier, then why not? ;)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#6
VBnet

VBnet

    Newbie

  • Members
  • PipPip
  • 18 posts

Xav said:

Lol - but if it's easier, then why not? ;)
because i dont mind typing 3 lines of coding

#7
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I thought you like to keep tutorials simple? :)

+rep for the tutorial.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#8
VBnet

VBnet

    Newbie

  • Members
  • PipPip
  • 18 posts

Xav said:

I thought you like to keep tutorials simple? :)

+rep for the tutorial.
Yeah i do :p