.net,winform将指定控件移动到指定位置

'''


''' 将指定控件移动到指定位置
'''

''' 控件
''' 目标位置(父容器坐标系)
''' 移动次数
''' 移动耗时
'''
Sub MoveTo(ByVal c As Control, ByVal p As Point, ByVal movestep As Integer, ByVal time As Integer)
Dim l As Point = c.Location
Dim xspeed As Single = (p.X - l.X) / movestep
Dim yspeed As Single = (p.Y - l.Y) / movestep
Dim steptime As Single = 1000 * time / movestep
For i As Integer = 1 To movestep
c.Left = l.X + i * xspeed
c.Top = l.Y + i * yspeed
Threading.Thread.Sleep(steptime)
My.Application.DoEvents()
Next
End Sub

测试代码


Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
MoveTo(Button1, e.Location, 100, 2)
End Sub

相关文档
最新文档