当前位置:编程学习 > C#/ASP.NET >>

求助字幕的移动

 private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "开始")
            {
                button1.Text = "停止";
                timer1.Enabled =true ;
            }
            else
            {
                button1.Text = "开始";
                timer1.Enabled =false ;
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            int a = label1.Location.X-10;
            int b = label1.Location.Y;
            if (a<-label1.Width )
               a=this .Width ;
            label1.Location = new Point(a, b);
        }
    }
为什么还是不能移动字幕呢?是不是要设置label的属性呢? --------------------编程问答--------------------     private void button2_Click(object sender, EventArgs e)
        {
            if (this.button2.Text == "开始")
            {
                this.button2.Text = "结束";
                this.timer1.Enabled = true;
            }
            else
            {
                this.button2.Text = "开始";
                this.timer1.Enabled = false;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int x = this.label1.Location.X - 10;
            int y = this.label1.Location.Y;
            if (x <= this.label1.Width)
            {
                x = this.Width;
            }
            this.label1.Location = new Point(x,y);
        } --------------------编程问答--------------------

            int a = label1.Location.X - 10;
            int b = label1.Location.Y;
            if (a < -label1.Width)
                a = this.Width;
            this.Invoke(new Action(() =>
            {
                label1.Location = new Point(a, b);
            }));

--------------------编程问答-------------------- 完整的代码:

        System.Timers.Timer timer = new System.Timers.Timer(100);

        public Form1()
        {
            InitializeComponent();
            timer.Elapsed += timer_Elapsed;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "开始")
            {
                button1.Text = "停止";
                timer.Enabled = true;
            }
            else
            {
                button1.Text = "开始";
                timer.Enabled = false;
            }
        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            int a = label1.Location.X - 10;
            int b = label1.Location.Y;
            if (a < -label1.Width)
                a = this.Width;
            this.Invoke(new Action(() =>
            {
                label1.Location = new Point(a, b);
            }));
        }

--------------------编程问答-------------------- System.Timers.Timer timer = new System.Timers.Timer(100);
这句是不是放在Using后面呢?
放在using后面的话会出错。。
注释掉这句还是不行,字幕动不了 --------------------编程问答--------------------
引用 3 楼  的回复:
完整的代码:

C# code

        System.Timers.Timer timer = new System.Timers.Timer(100);

        public Form1()
        {
            InitializeComponent();
            timer.Elapsed += timer_Elap……

System.Timers.Timer timer = new System.Timers.Timer(100);
这句是不是放在Using后面呢?
放在using后面的话会出错。。
注释掉这句还是不行,字幕动不了 --------------------编程问答--------------------
引用 5 楼  的回复:
引用 3 楼  的回复:
完整的代码:

C# code

System.Timers.Timer timer = new System.Timers.Timer(100);

public Form1()
{
InitializeComponent();
timer.Elapsed += timer_Elap……

System.Timers.Timer timer =……

怎么会放到using后面……
难道你连基本的C#语法还没了解?
这是Form的一个字段,放在class内部就行了…… --------------------编程问答--------------------
引用 6 楼  的回复:
引用 5 楼 的回复:

引用 3 楼 的回复:
完整的代码:

C# code

System.Timers.Timer timer = new System.Timers.Timer(100);

public Form1()
{
InitializeComponent();
timer.Elapsed += timer_Elap……

System.Timers.……

呵呵  我是刚开始学的,还有很多不懂得的还要请教诸位哦!

这句放在放在class内部也不行哦!
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,