使用截屏程序VB.net预览桌面

时间:2015-03-13 10:35:07

标签: vb.net

我只是想知道。我该如何调整我的代码

        Dim Size As Rectangle
    Dim Capt As System.Drawing.Bitmap
    Dim Pic As Graphics

    Do While 1
        Size = Form2.Bounds
        Capt = New System.Drawing.Bitmap(Size.Width, Size.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
        Pic = Graphics.FromImage(Capt)
        Pic.CopyFromScreen(Size.X, Size.Y, 0, 0, Size.Size, CopyPixelOperation.MergeCopy)
        PictureBox1.Image = Capt
    Loop

显示表单所看到的图片。 更清楚的理解是 http://i.stack.imgur.com/euJmM.png

我有两种形式,一种是图片框,另一种是透明形式,我希望图片框能够显示第二种形式通过透明部分看到的内容(可以只是整个表格)边界和所有)。然后继续将其保存到文件中,我以为我的代码会自动更新到第二个表单在屏幕上的位置并自动填充图片框,但显然不是。

1 个答案:

答案 0 :(得分:0)

这是一个可能的解决方案,如果我理解正确的话,这可以达到你想要的效果。

如果您有任何疑问,请随时提出:

Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.BackColor = Color.Magenta
        Me.TransparencyKey = Color.Magenta
    End Sub
End Class
Imports System.Threading

Public Class Form1
    Private ScreenShot As Thread
    Dim F2 As Form2
    Private Sub Capt_Click(sender As Object, e As EventArgs) Handles Capt.Click
        CheckForIllegalCrossThreadCalls = False
        F2 = New Form2
        F2.Show()
        ScreenShot = New Thread(AddressOf RefreshView)
        ScreenShot.IsBackground = True
        ScreenShot.Start()
    End Sub

    Private Sub RefreshView()
        Dim Size As Rectangle
        Dim Capt As System.Drawing.Bitmap
        Dim Pic As Graphics
        Do While 1
            Size = F2.RectangleToScreen(F2.ClientRectangle)
            Capt = New System.Drawing.Bitmap(Size.Width, Size.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            Pic = Graphics.FromImage(Capt)
            Dim boundsLeft = Size.X
            Dim boundsTop = Size.Y
            Pic.CopyFromScreen(boundsLeft, boundsTop, 0, 0, Size.Size, CopyPixelOperation.MergeCopy)
            pictureBox1.Image = Capt
        Loop
    End Sub
End Class