主题:基础的Label控件问题
Temiral
[专家分:50] 发布于 2005-09-07 19:59:00
怎样利用Timer控件控制Label控件做出跑马灯效果
(希望能做到Label内容从右到左移动或者从上到下移动)
因为刚自学不久,所以恳请附上代码.在此先谢了!
回复列表 (共4个回复)
沙发
ryowu [专家分:6470] 发布于 2005-09-08 09:22:00
http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/Timers/Timer/Timer.src&file=CS\Timer.cs&font=3
这是一个计时器的例子,仅作参考
板凳
宝宝啊呜 [专家分:990] 发布于 2005-09-08 15:04:00
Dim x, y, k As Integer
Dim flag As Boolean = True '跑马灯方向朝左
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = 150 : y = 150
lblMsg.Location = New Point(x, y)
lblMsg.BackColor = Color.Aqua
lblMsg.AutoSize = True
lblMsg.Font = New System.Drawing.Font("楷体_GB2312", 20, FontStyle.Bold)
lblMsg.Text = "全OK资讯网"
Timer1.Enabled = True
Timer1.Interval = 10
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblLocation.Text = "'跑马灯'位置:" & lblMsg.Left
If flag = True Then ' 左移
x -= 1
lblMsg.Location = New Point(x, y)
lblDirection.Text = "目前方向 : 往左移"
If (Integer.Parse(lblMsg.Left) <= 0) Then
flag = False
End If
Else
x += 1
lblMsg.Location = New Point(x, y)
lblDirection.Text = "目前方向 : 往右移 "
If (Integer.Parse(lblMsg.Left) + Integer.Parse(lblMsg.Width) >= Integer.Parse(Me.Width)) Then
flag = True '左移
End If
End If
End Sub
这个是很完整的代码,中间具体的参数,你自己看下吧,我也是从书内的光盘里直接弄过来的,呵呵[em4]
3 楼
Temiral [专家分:50] 发布于 2005-09-11 18:29:00
代码实现不了我想做的效果,我想做的效果是用Timer事件控制Label控件的内容从右到左移动并且循环.
4 楼
宝宝啊呜 [专家分:990] 发布于 2005-09-14 08:42:00
循环就不会了,这个只能从右移到左,然后在从左移到右……[em8],再……
我来回复