2020年5月5日 星期二

VB.net 簡易截圖程式 [Screenshoter]

一個 Form 一個 PictureBox 足以~

    Public Class Form1
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click '點擊執行
            Opacity = 0 '視窗透明(不然會照到自己)
            Dim ScrnPB As PictureBox = PictureBox1
            Dim ScrnSize As Size = My.Computer.Screen.Bounds.Size
            Dim ScrnImage As New Bitmap(ScrnSize.Width, ScrnSize.Height)
            Dim g As Graphics = Graphics.FromImage(ScrnImage)

            g.CopyFromScreen(New Point(Me.Left + 8, Me.Top + 30), New Point(0, 0), ScrnSize) '以自己視窗為始點修正偏移
            Dim dc As IntPtr = g.GetHdc
            g.ReleaseHdc(dc)
            With ScrnPB '使大小相同
                .Size = ScrnSize
                .Image = ScrnImage
            End With
            Opacity = 70 '視窗透明度70%
        End Sub
    End Class

沒有留言:

張貼留言