在c#windows窗体中自动移动标签 [英] Auto move a label in c# windows Form

查看:195
本文介绍了在c#windows窗体中自动移动标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#windows中自动从左到右移动标签表单编程

how to auto move a label left to right in c# windows Form programming

推荐答案

使用定时器控件并在每个定时器间隔内递增标签左侧位置,直到达到右边。
Use timer control and increment the label left position in each timer interval until it reaches the right end.


我采取了非常粗略的方法来做到这一点:



1.我在表格上添加了标签。

2.在表格上添加一个计时器。

3.将计时器超时设置为100ms。

4.将以下代码添加到表格



I took a very crude approach to do this:

1. I added the label on the form.
2. added a timer on the form.
3. set the timer timeout to 100ms.
4. added the following code to the form

public Form1()
        {
            InitializeComponent();
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Location = new Point(label1.Location.X + 5, label1.Location.Y);

            if(label1.Location.X  > this.Width)
            {
                label1.Location = new Point(0 - label1.Width, label1.Location.Y);
            }
        }





这给了我一个从左到右的滚动。一旦它离开右侧的形状,它也会再次出现在左边。



试一试,看看你是否能让它发挥作用。



This gave me a scrolling left to right. also it reappears on left once it goes out of form on right side.

Try it and see if you could get this to work.

private void timer1_Tick(object sender, EventArgs e)
{
    label1.Left = label1.Left + 10;
}

private void Form1_Load(object sender, EventArgs e)
{
    timer1.Enabled = true;
}


这篇关于在c#windows窗体中自动移动标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆