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

Winform 关于文字移动的有关问题!

2013-01-23 
Winform 关于文字移动的问题!!??小弟现在想做一个关于label从下往上移动的窗体。基本功能已实现,但效果不理

Winform 关于文字移动的问题!!??
小弟现在想做一个关于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,768 winform label 从下往上移动 timer
[解决办法]
if (LPos.Y < FHeight)
=>
if (LPos.Y+label1.Height < FHeight)
[解决办法]
不要用Timer。timer有段时间停顿的。
你用一个线程做。那个不会停顿的。
[解决办法]

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();

        }

热点排行