日期:2014-05-17  浏览次数:20867 次

怎么在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 = "开始";