VB2010 如何拖动没有标题栏的窗口?
窗体标题栏添加了一个picturebox,然后导入了一个图片。代码出错了,那里有错。PublicClassForm1PrivateSubPictureBox1_Mouse...
窗体标题栏添加了一个picturebox, 然后导入了一个图片。
代码出错了,那里有错。
Public Class Form1
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then
Dim mousePos As Point = sender.findform().MousePosition
mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)
sender.findform().Location = mousePos
End If
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
mouse_offset = New Point(e.X, e.Y)
End Sub
End Class 展开
代码出错了,那里有错。
Public Class Form1
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then
Dim mousePos As Point = sender.findform().MousePosition
mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)
sender.findform().Location = mousePos
End If
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
mouse_offset = New Point(e.X, e.Y)
End Sub
End Class 展开
2个回答
展开全部
Public Class Form1
Dim mouse_offset As Point
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then
Dim mousePos As Point = sender.findform().MousePosition
mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)
sender.findform().Location = mousePos
End If
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
mouse_offset = New Point(e.X, e.Y)
End Sub
End Class
Dim mouse_offset As Point
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then
Dim mousePos As Point = sender.findform().MousePosition
mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)
sender.findform().Location = mousePos
End If
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
mouse_offset = New Point(e.X, e.Y)
End Sub
End Class
追问
还是有问题,不能标题栏的任何地点按住拖动,按住后拖动就鼠标移动到 0,0 点
追答
:)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询