开发者

Creation of Marquee in .NET windows application

I have to create 开发者_如何学Goa marquee in a .NET windows application. What is the best to do this with C#?


here is the simple code on how you can do marquee in C#

        private int xPos=0;

        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Width == xPos)
            {
                //repeat marquee
                this.lblMarquee.Location = new System.Drawing.Point(0, 40);
                xPos = 0;
            }
            else
            {
                this.lblMarquee.Location = new System.Drawing.Point(xPos, 40);
                xPos++;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }


Just place a ProgressBar control and change its Style to Marquee from the designer. You'll see the animation immediately.

If you're referring to text marquee, just place a Label control and user the Timer Class to increment the Location.X property of the label. When X coordinate is equal to the size of the control, just reset it and start over.


    private void button_Click(object sender, EventArgs e)
    {
        int j = 100;
        for (int i = 0; i < j; i++)
        {
            Thread.Sleep(5);
            label3.Location = new System.Drawing.Point(0 + i, 111);
            label3.Visible = true;

        }
        for (int i = j; i-- > 0; )
        {
            Thread.Sleep(15);
            label3.Location = new System.Drawing.Point(0 + i, 111);
            label3.Visible = true;
            if (i < 1)
                button_Click(sender, e);
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜