16 March 2014

How to make your own Screen Shot Application using VB.Net

Screen Capture គឺជាកម្មវិធីថត Screen Computer ជាលក្ខណរូបភាព។ តាមពិតទៅគឺមានកម្មវិធីច្រើនណាស់សំរាប់ថត Screen Computer ប៉ុន្តែថ្ងៃនេះខ្ញុំគ្រាន់តែចង់បង្ហាញអ្នកពីវិធីសំរាប់បង្កើតវា។
ហើយខ្ញុំសូមលើកយកកម្មវិធី Visual Basic មកបង្ហាញពីវិធីបង្កើតកម្មវិធីនេះ។ សូមអនុវត្តដូចខាងក្រោម ៖
1.គូស Label1, Texbox1, Button1 និង Timer1 ដូចក្នុងរូបខាងក្រោម

2. Double Click លើ Button1 (Capture) រួចសរសេរកូដដូចខាងក្រោម
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Enabled = False
        Me.MinimizeBox = True
        Timer1.Start()
End Sub

3. Double Click លើ Timer1 រួចសរសេរកូដដូចខាងក្រោម
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim snappit As String = 0
        TextBox1.Text -= snappit + 1
        If TextBox1.Text = 0 Then
            Me.Hide()
        End If
        If TextBox1.Text = -2 Then
            Try
                Dim screenshot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                Dim screengrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screengrab)
                g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenshot)
                screengrab.Save("snap.jpg")
                MsgBox("your screen has been snapped and the snap was saved", MsgBoxStyle.Information, "SuperScreenShot")
                Me.Close()
            Catch ex As Exception
                MsgBox("sorry unable to snap your screen and save at the moment please try again later", MsgBoxStyle.Critical, "Warning!")
            End Try
        End If
 End Sub

4. សាកល្បង Run Application and Enjoy your testing :)

*** Note : បញ្ចូលចំនួនវិនាទីក្នុង Textbox ដើម្បីកំណត់វិនាទីនៃការថត បន្ទាប់មកចុចលើ Button Capture
រូបថតដែលថតរួចអ្នកអាចស្វែងរកក្នុង Folder Bin


SamnengIT © 2014-2015SamnengIT