小弟现在想做一个关于label从下往上移动的窗体。基本功能已实现,但效果不理想,不理想在哪呢?在一段文字走完了以后,会出现一屏的空白。望大侠们赐教下!!!基本代码如下:
  int loc_text = 0;
 private void timer1_Tick(object sender, EventArgs e)
        {
            int FWidth = this.panel1.Width;
            int FHeight = this.panel1.Height;            Point LPos = new Point(this.label1.Location.X, this.label1.Location.Y);
            if (LPos.Y < FHeight)
            {
                if (LPos.Y < -loc_text)
                {
                    this.label1.Location = new Point(0, this.Height - 72); return;
                }                this.label1.Location = new Point(LPos.X, LPos.Y - 10);
                return;
            }
            else
            {
                this.label1.Location = new Point(0, 0);
            }
        }
 private void JCZ_SendNews_Load(object sender, EventArgs e)
        {
            this.label1.Location = new Point(0, this.Height - 72);
            label1.Text = "      紧急通知\n由于近期物价高涨,燃油价格也高涨,反正就是什么都贵了。为了体现中国加入WTO与国际接轨的精神,本店铺也将提价10%,表示对国家的物质文明建设的贡献!";            int sumChar = label1.Text.Length;
            int rowCount = (sumChar / 10) + 1;
            label1.Height = rowCount * 100;
            loc_text = rowCount * 100;
            label1.Size = new Size(1024, label1.Height);
            label1.Font = new Font("黑体", 72);
            label1.ForeColor = Color.Red;
            this.BackColor = Color.Black;            this.timer1.Enabled = true;
            this.timer1.Interval = 300;
            this.timer1.Start();        }
窗体的尺寸为:1024,768winformlabel从下往上移动timer

解决方案 »

  1.   

    if (LPos.Y < FHeight)
    =>
    if (LPos.Y+label1.Height < FHeight)
      

  2.   

    不要用Timer。timer有段时间停顿的。
    你用一个线程做。那个不会停顿的。
      

  3.   


    if (LPos.Y < -loc_text)判断不对,应该是
    if (LPos.Y < -label1.Height)        private void timer1_Tick(object sender, EventArgs e)
            {
                int FWidth = this.panel1.Width;
                int FHeight = this.panel1.Height;            Point LPos = this.label1.Location;
                if (LPos.Y < FHeight)
                {
                    if (LPos.Y < -label1.Height)
                    {
                        this.label1.Location = new Point(0, this.Height - 72);
                        return;
                    }                this.label1.Location = new Point(LPos.X, LPos.Y - 10);
                }
                else
                {
                    this.label1.Location = new Point(0, 0);
                }
            }
            private void JCZ_SendNews_Load(object sender, EventArgs e)
            {
                this.label1.Location = new Point(0, this.Height - 72);
                label1.Text = "      紧急通知\n由于近期物价高涨,燃油价格也高涨,反正就是什么都贵了。为了体现中国加入WTO与国际接轨的精神,本店铺也将提价10%,表示对国家的物质文明建设的贡献!";            int sumChar = label1.Text.Length;
                int rowCount = (sumChar / 10) + 1;
                label1.Height = rowCount * 100;
                label1.Size = new Size(1024, label1.Height);
                label1.Font = new Font("黑体", 72);
                label1.ForeColor = Color.Red;
                //this.BackColor = Color.Black;
                this.timer1.Enabled = true;
                this.timer1.Interval = 300;
                this.timer1.Start();        }
      

  4.   

     int loc_text = 0;
            Label label2 = new Label();
            bool Bo = true;
            bool Bol = true;
          
            private void timer1_Tick(object sender, EventArgs e)
            {
                int FWidth = this.panel1.Width;
                int FHeight = this.panel1.Height;            Point LPos = new Point(this.label1.Location.X, this.label1.Location.Y);
                if (LPos.Y < FHeight)
                {
                    if (LPos.Y < -(loc_text / 2))
                    {
                        if (Bol)
                        {                        if (Bo)
                            {
                                label2.Location = new Point(0, this.Height - 72);
                                panel1.Controls.Add(label2);
                                timer2.Enabled = true;
                                timer2.Interval = 300;
                                timer2.Start();
                                Bo = false;
                                Bol = false;
                            }
                        }
                    }
                    if (LPos.Y < -loc_text)
                    {
                        timer1.Stop();
                    }
                    this.label1.Location = new Point(LPos.X, LPos.Y - 10);
                    return;
                }
                else
                {
                    this.label1.Location = new Point(0, 0);
                }
            }        private void timer2_Tick(object sender, EventArgs e)
            {
                int FWidth = this.panel1.Width;
                int FHeight = this.panel1.Height;            Point LPos = new Point(this.label2.Location.X, this.label2.Location.Y);
                if (LPos.Y < FHeight)
                {
                    if (LPos.Y < -(loc_text / 2))
                    {
                        if (!Bo)
                        {
                            timer1.Start();
                            this.label1.Location = new Point(0, this.Height - 72);
                            Bo = true;
                        }                }
                    if (LPos.Y < -loc_text)
                    {
                        timer2.Stop(); Bol = true;
                    }                this.label2.Location = new Point(LPos.X, LPos.Y - 10);
                    return;
                }
                else
                {
                    this.label2.Location = new Point(0, 0);
                }
            }        private void JCZ_SendNews_Load(object sender, EventArgs e)
            {
                this.label1.Location = new Point(0, this.Height - 72);
                label1.Text = "      紧急通知\n由于近期物价高涨,燃油价格也高涨,反正就是什么都贵了。为了体现中国加入WTO与国际接轨的精神,本店铺也将提价10%,表示对国家的物质文明建设的贡献!";            int sumChar = label1.Text.Length;
                int rowCount = (sumChar / 10) + 1;
                label1.Height = rowCount * 100;
                loc_text = rowCount * 100;
                label1.Size = new Size(1024, label1.Height);
                label1.Font = new Font("黑体", 72);
                label1.ForeColor = Color.Red;            label2.Text = label1.Text;
                sumChar = label2.Text.Length;
                rowCount = (sumChar / 10) + 1;
                label2.Height = rowCount * 100;
                label2.Size = new Size(1024, label2.Height);
                label2.Font = new Font("黑体", 72);
                label2.ForeColor = Color.Red;            this.BackColor = Color.Black;            this.timer1.Enabled = true;
                this.timer1.Interval = 300;
                this.timer1.Start();        }解决了……。办法是通过,两个label,的涵接来实现……。散分,结贴!