窗口自动调整使用鼠标移动鼠标、窗口

2023-09-06 11:37:22 作者:凌乱的、心跳

所以,我有以下的应用程序,有3个按钮。 1让我打开一个新的窗口,我可以调整这个窗口,我想,然后preSS按钮2,以捕获窗口大小的图片。我的问题是我怎么才能让这个当我preSS按钮1,将显示窗体2但随后的Form2的窗口,将鼠标移动,当我点击并拖动的大小,然后松开它需要该地区像这样的在这里

这是它目前的样子,我必须手动调整窗口

Form1.vb的

 私人小组的button1_Click(发送者为对象,E作为EventArgs的)把手Button1.Click
        Form2.Show()
    结束小组

    私人小组Button2_Click(发送者为对象,E作为EventArgs的)把手Button2.Click
        昏暗的范围作为矩形
        昏暗的屏幕截图作为System.Drawing.Bitmap
        昏暗的图形作为图形

        边界= Screen.PrimaryScreen.Bounds
        截图=新System.Drawing.Bitmap(Form2.Bounds.Width,Form2.Bounds.Height,System.Drawing.Imaging.PixelFormat.Format32bppArgb)

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

        PictureBox1.Image =截图
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    结束小组
 

Form2.vb

 公共类窗体2

    私人小组Form2_Load(发送者为对象,E作为EventArgs的)把手MyBase.Load

    结束小组
末级
 
罗技m545怎么调鼠标移动速度

解决方案

检查这两种方法:

鼠标捕获答案@ SO 。这基本上是一个链接到MSDN 。此外这个。

  

Control类的捕捉属性指定控件是否已捕获鼠标。要确定当控件失去鼠标捕获,处理MouseCaptureChanged事件。

如何捕获一种形式之外鼠标的位置?

So I have the following app that has 3 buttons. 1 allows me to open a new window where I can resize this window to that I want, and then press button 2 to capture a picture of that window size. My question is how can I make it so that when i press button 1 it will show Form2 but then the Form2 window will move with the mouse and when i click and drag for the size then release it takes that region like this here

This is what it currently looks like and I have to manually resize the window

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

解决方案

Check these two methods:

Mouse capture answer @ SO. This is basically a link to MSDN. Also this one.

The Capture property of the Control class specifies whether a control has captured the mouse. To determine when a control loses mouse capture, handle the MouseCaptureChanged event.

How to capture mouse position outside of a form?