Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True '设置处理窗体的鼠标事件
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Button1.Location = New Point(e.X, e.Y) '将控件的位置设成鼠标的位置,控件即随鼠标移动
End Sub
Me.KeyPreview = True '设置处理窗体的鼠标事件
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Button1.Location = New Point(e.X, e.Y) '将控件的位置设成鼠标的位置,控件即随鼠标移动
End Sub
博客展示了VB.NET代码,通过设置窗体处理鼠标事件,在鼠标移动时将Button1控件的位置设为鼠标位置,从而实现控件随鼠标移动的效果。
1821

被折叠的 条评论
为什么被折叠?



