所以我删除了程序的边框以将自己的自定义ui放入其中,所以我当然要想办法调整它的大小。我是通过使用一个按钮来做到这一点的,但是当它在屏幕的右下方时,程序会增加它的大小,但它仍然可以调整大小,当它在左上方时它仍然这样做只是增加了一点点。
我也知道还有其他方法,但对我来说这是最简单的方法,只是因为某种原因按钮增加了它自己的大小。
这里是代码:
Private Sub tim_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tim.Tick
Me.Size = MousePosition
End Sub
Private Sub res_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles res.MouseDown
tim.Enabled = True
End Sub
Private Sub res_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles res.MouseUp
tim.Enabled = False
End Sub
答案 0 :(得分:0)
如果我理解你的意图,那么你缺少的是Control.PointToClient
方法。它将MousePosition从屏幕上的坐标转换为表单上的坐标。
这是您的代码的修改版本。
Private Sub tim_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tim.Tick
Dim curpos As Point = PointToClient(MousePosition)
Size = New Size(curpos.X + (Size.Width - ClientSize.Width), curpos.Y + (Size.Height - ClientSize.Height))
'if your form has no border you can skip the above and just use:
' Size = PointToClient(MousePosition)
End Sub
Private Sub res_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles res.MouseDown
Cursor.Position = PointToScreen(ClientRectangle.Size)
Cursor = Cursors.SizeNWSE
tim.Enabled = True
End Sub
Private Sub res_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles res.MouseUp
Cursor = Cursors.Default
tim.Enabled = False
End Sub