我在面板中创建了一个标签,并希望垂直移动它。 水平移动使用:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Start()
If lbl1.Location.X + lbl1.Width < 0 Then
lbl1.Location = New Point(Panel5.Width, lbl1.Location.Y)
Else
lbl1.Location = New Point(lbl1.Location.X - 4, lbl1.Location.Y)
End If
End Sub
正如您在上面的代码(X)中看到的那样,(Y)用于左右绘图点。顶部和底部的绘图点是什么
答案 0 :(得分:0)
您的水平例程:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If lbl1.Location.X + lbl1.Width < 0 Then
lbl1.Location = New Point(Panel5.Width, lbl1.Location.Y)
Else
lbl1.Location = New Point(lbl1.Location.X - 4, lbl1.Location.Y)
End If
End Sub
转换为垂直例程:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If lbl1.Location.Y + lbl1.Height < 0 Then
lbl1.Location = New Point(lbl1.Location.X, Panel5.Height)
Else
lbl1.Location = New Point(lbl1.Location.X, lbl1.Location.Y - 4)
End If
End Sub
答案 1 :(得分:0)
采纳您的想法并根据自己的需要进行修改:
Private isFirstTime As Boolean = True
Public Sub RunningText(ByVal lbl As Label, ByVal pnl As Panel, Optional fromRightBottom As Boolean = True, Optional ByVal isHorizontal As Boolean = True)
If isFirstTime Then
If isHorizontal Then
If fromRightBottom Then
lbl.Location = New Point(pnl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(-1 * lbl.Width, lbl.Location.Y)
End If
Else
If fromRightBottom Then
lbl.Location = New Point(lbl.Location.X, pnl.Height)
Else
lbl.Location = New Point(lbl.Location.X, 0)
End If
End If
isFirstTime = False
End If
If isHorizontal Then
If fromRightBottom Then
If lbl.Location.X + lbl.Width < 0 Then
lbl.Location = New Point(pnl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(lbl.Location.X - 4, lbl.Location.Y)
End If
Else
If lbl.Location.X + pnl.Width > lbl.Width + pnl.Width Then
lbl.Location = New Point(-1 * lbl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(lbl.Location.X + 4, lbl.Location.Y)
End If
End If
Else
If fromRightBottom Then
If lbl.Location.Y + lbl.Height < 0 Then
lbl.Location = New Point(lbl.Location.X, pnl.Height)
Else
lbl.Location = New Point(lbl.Location.X, lbl.Location.Y - 4)
End If
Else
If lbl.Location.Y + lbl.Height > lbl.Height + pnl.Height Then
lbl.Location = New Point(lbl.Location.X, 0)
Else
lbl.Location = New Point(lbl.Location.X, lbl.Location.Y + 4)
End If
End If
End If
End Sub