首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

如何在winform中让一个label左右循环飘动

2013-12-28 
怎么在winform中让一个label左右循环飘动我想在窗体上飘一行文字,而且是从左到右,但是文字会飘出窗体外边

怎么在winform中让一个label左右循环飘动
我想在窗体上飘一行文字,而且是从左到右,但是文字会飘出窗体外边看不见了,
我需要飘出去的那部分从右边在接着飘出来可以吗?
[解决办法]
这个效果叫做走马灯
走马灯效果搜索
[解决办法]
label
写个循环么。
用timer,每隔一段时间left-1.。。
判断left<0
在把它移动到最右边
[解决办法]
你判断一下它的location,如果跑出去了就给它重置到左边
[解决办法]


//form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        public int direction = -1;
        bool started;
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!started)
            {
                started = true;
                timer1.Start();
                button1.Text = "停止";
            }
            else
            {
                started = false;
                timer1.Stop();
                button1.Text = "开始";
            }
            }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            if (label1.Left <= 0)
                direction = 1;
            if (label1.Right >= this.Width)
                direction = -1;
            label1.Left += direction * 2;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 f2= new Form2();
            f2.Owner = this;
            f2.ShowDialog();

        }
     

    }
}


//form2

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
    public partial class Form2 : Form
    {


        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
                ((Form1)this.Owner).direction = -1;
            else
                ((Form1)this.Owner).direction = 1;
            this.Close();

        }

    }
}


[解决办法]
Winform实现滚动字幕 
http://blog.csdn.net/jayinit/article/details/6387527
http://hi.baidu.com/wxs198766/item/8e5b9517a93f0a49e75e06ae

热点排行