问题描述
- VB.net中在窗体设置一个标签,让他沿窗体八字形滚动,如何让他一接触边框便折返
-
RT,现在是沉下去老久才会上来
Public Class Form1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Timer1.Enabled = False
Label1.Top = 0
Label1.Left = 0
End SubPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Timer1.Enabled = True End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Call mymove() End Sub Sub mymove() Static m As Double m = (Me.Height - Label1.Height) / (Me.Width - Label1.Width) Timer1.Interval = Val(TextBox1.Text) Dim x As Double, y As Double Static flag As Integer If (Label1.Top <= 0 And Label1.Left <= 0 Or Label1.Top <= 0 And Label1.Left >= Me.Width - Label1.Width) Then flag = 0 ElseIf (Label1.Top >= Me.Height - Label1.Height And Label1.Left <= 0) Then flag = 1 ElseIf (Label1.Top >= Me.Height - Label1.Height And Label1.Left >= Me.Width - Label1.Width) Then flag = 2 End If Select Case flag Case 0 x = 100 * m y = 0 Case 1 x = -100 * m y = 100 Case 2 x = -100 * m y = -100 End Select Label1.Top += x Label1.Left += y Label2.Text = x Label3.Text = y End Sub
End Class
解决方案
Label1.Top >= Me.Height - Label1.Hight加入条件
解决方案二:
timer定时,移动控件。。。
时间: 2024-10-31 11:00:29