用鼠标移动自动调整窗口大小

时间:2013-12-06 21:34:47

标签: .net vb.net

所以我有以下有3个按钮的应用程序。 1允许我打开一个新窗口,我可以将此窗口调整为我想要的大小,然后按下按钮2以捕获该窗口大小的图片。我的问题是我怎么能这样做,当我按下按钮1它将显示Form2但随后Form2窗口将移动鼠标,当我点击并拖动大小然后释放它需要像这样的区域 enter image description here

这是目前的样子,我必须手动调整窗口大小 enter image description here

Form1.vb的

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim bounds As Rectangle
        Dim screenshot As System.Drawing.Bitmap
        Dim graph As Graphics

        bounds = Screen.PrimaryScreen.Bounds
        screenshot = New System.Drawing.Bitmap(Form2.Bounds.Width, Form2.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)

        graph = Graphics.FromImage(screenshot)
        graph.CopyFromScreen(Form2.Bounds.X, Form2.Bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)

        PictureBox1.Image = screenshot
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub

Form2.vb

Public Class Form2

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

检查以下两种方法:

  1. Mouse capture answer @ SO。这基本上是a link to MSDN。还this one

      

    Control类的Capture属性指定控件是否捕获了鼠标。要确定控件何时失去鼠标捕获,请处理MouseCaptureChanged事件。

  2. How to capture mouse position outside of a form?