小弟通过如下代码实现了Label文字从右至左滚动,但这种滚动是要等Label完全消失在左边时,再从右边出来,
现想实现不间断的滚动,就是说,Label第一个字进入最左边时,从最右边显示进入最左边的字,实现不间断,完整显示!请高手指点,给小弟一个思路或代码,谢稿int ScreenWidth = SystemInformation.PrimaryMonitorMaximizedWindowSize.Width;
int ScreenHeight = SystemInformation.PrimaryMonitorMaximizedWindowSize.Height;
Point MyPos = new Point(this.label1.Location.X, this.label1.Location.Y);
if (MyPos.X + Width + this.label1.Width >= ScreenWidth)
{
    this.label1.Location = new Point(MyPos.X - 20, 0);
    return;
}
else
{
    this.label1.Location = new Point(this.Width, 0);
}

解决方案 »

  1.   

    做两个文本内容一样的Label1(左)、Label2(右),他们之间的X轴坐标相差 = 屏幕宽度;
    当Label1(左)完全消失在左边时,this.Label1(左).Location = new Point(this.Width, 0);
    当Label2(右)完全消失在左边时,this.Label2(右).Location = new Point(this.Width, 0);
      

  2.   

    你要做字幕对吧,给你一个我做的.
            Thread th = null;
            private void frm_Sub_Load(object sender, EventArgs e)
            {
                this.Width = Screen.PrimaryScreen.Bounds.Width;
                Random r = new Random();
                this.Location = new Point(0,r.Next(0,Screen.PrimaryScreen.Bounds.Height-this.Height));
                this.label1.Width = this.Width;
                label1.Height = this.Height-10;
                label1.Location = new Point(this.Width, 5);
                label1.Top = 0;
                label1.Font = new Font(FontFamily.GenericSansSerif, (float)(((this.Height - 10) * 72) / 96));
                label1.Text = "你好啊~~~~~~~~~~~abc ABC";
                th = new Thread(new ThreadStart(runSub));
                th.IsBackground = true;
               th.Start();
            }
            private void runSub()
            {
                while (true)
                {
                    if (this.InvokeRequired)
                    {
                        try
                        {
                            this.Invoke(new subTitle(sub));
                        }
                        catch { }
                    }
                    Thread.Sleep(10);
                }
            }
            private delegate void subTitle();
            private void sub()
            {
                if (label1.Left > -label1.Width)
                {
                    label1.Left -=1;
                }
                else
                {
                    label1.Left = this.Width;
                }
            }
      

  3.   

    不要去移location这样会一卡一卡,你应该用drawtext的GDI方法把文字画出来,非常的简单,试试就会
      

  4.   

    有没有详细的GDI写法,小弟不太会,还望大哥仔细指导,谢谢
      

  5.   


    Graphic g=this.createGraphic();
    g.drawString("Hello",this.font, new Point(50,50));g.dispose();
      

  6.   

    很简单的,你BAIDU 一下吧!
      

  7.   

    修改你的代码,增加Label2,把它的Location放到与Label差ScreenWidth的地方,再一起向左滚动this.label1.Text ="AA";//增加如下
    this.label2.Text ="AA";
    this.label2.Location = new Point(this.label1.Location.X + Width, 0);int ScreenWidth = SystemInformation.PrimaryMonitorMaximizedWindowSize.Width;
    int ScreenHeight = SystemInformation.PrimaryMonitorMaximizedWindowSize.Height;
    Point MyPos = new Point(this.label1.Location.X, this.label1.Location.Y);//增加如下
    Point MyPos2 = new Point(this.label2.Location.X, this.label2.Location.Y);if (MyPos.X + Width + this.label1.Width >= ScreenWidth)
    {    this.label1.Location = new Point(MyPos.X - 20, 0);
        //增加如下
        this.label2.Location = new Point(MyPos2.X - 20, 0);
        return;
    }
    else
    {
        //修改如下
        this.label1.Location = new Point(this.Width-this.label1.Width-40, 0);
        //增加如下
        this.label2.Location = new Point(this.label1.Location.X + Width, 0);
    }
      

  8.   

    我的方法不会卡 ,试试就知道啦,我也曾经尝试过用GDI画,画面闪烁不说,资源占用太高了.
      

  9.   


    GDI闪烁,那时因为你可以用缓冲阿,先画在内存的一块画布上,然后再 画到界面上来。那就不会闪烁了。
      

  10.   

    private void Form1_Load(object sender, EventArgs e)
      {
      this.label1.Location = new Point(0, 0);
      }
      int x= 0;
      bool ist = true;
      private void timer1_Tick(object sender, EventArgs e)
      {
      this.label1.Location = new Point(xPox,this.label1.Location.Y);
      if (x== this.Width-this.label1.Size.Width)
      ist = false;
      if(x==0)
      ist = true;
      if (ist)
      x++;
      else
      x--;
      }
    http://topic.csdn.net/u/20090606/10/5fc58b85-d448-4449-a46e-feb3fd9b0bcc.html
      

  11.   

    看了,感觉有点意思,给你写了一个using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    public class Form1
    {
    //code by dylike
    private string ADText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private int _ScrollLeft = 0;
    private Bitmap _textbmp;
    //本代码可以保证滚动流畅并且不闪画面,如需最佳效果,建议:Timer1.Interval=10
    //界面上放一Label控件,Autosize=fase,手动调整需要的宽度,高度将由代码控制,无需关注
    private void Timer1_Tick(System.Object sender, System.EventArgs e)
    {
    //Try
    using (_tmpBP == new Bitmap(Label1.Width, Label1.Height)) {
    using (Graphics G = Graphics.FromImage(_tmpBP)) {
    if (_textbmp != null) {
    _ScrollLeft = (_ScrollLeft <= -_textbmp.Width * 2 ? Label1.Width : _ScrollLeft - 1);
    // _ScrollLeft - 1中的1为每次移动速度,此处为每次移动1个像素
    using (System.Drawing.TextureBrush imgBrs = new System.Drawing.TextureBrush(_textbmp)) {
    imgBrs.WrapMode = Drawing2D.WrapMode.Tile;
    imgBrs.TranslateTransform(_ScrollLeft, 0); G.FillRectangle(imgBrs, new Rectangle(0, 0, Label1.Width, Label1.Height));
    }
    }
    }
    if (_tmpBP != null) {
    if (Label1.BackgroundImage != null)
    Label1.BackgroundImage = null;
    Label1.BackgroundImage = new Bitmap(_tmpBP);
    }
    }
    //Catch
    //End Try
    }
    private Bitmap _Gettextbitmap(Label Lb, string ScrollText)
    {
    try {
    this.DoubleBuffered = true;
    Bitmap BP = default(Bitmap);
    SizeF _Sz = default(SizeF);
    using (SolidBrush Brs = new SolidBrush(Lb.ForeColor)) {
    using (StringFormat _sf = new StringFormat()) {
    _sf.Alignment = StringAlignment.Center;
    _sf.LineAlignment = StringAlignment.Near;
    using (Graphics G = this.CreateGraphics) {
    _Sz = G.MeasureString(ScrollText, Lb.Font, new Size(99999, 99999), _sf);
    }
    }
    _Sz = new SizeF(_Sz.Width + 1, _Sz.Height + 1);
    int _w = 0;
    int _h = 0;
    Panel1.Size = _Sz.ToSize;
    _w = _Sz.Width;
    _h = _Sz.Height;
    BP = new Bitmap(_w + 100, _h);
    //此处的100为两个首尾相接的字幕间距
    using (Graphics G2 = Graphics.FromImage(BP)) {
    G2.DrawString(ScrollText, Lb.Font, Brs, 0, 0);
    }
    }
    return BP;
    } catch {
    return null;
    }
    } private void Form1_Shown(object sender, System.EventArgs e)
    {
    //注意,写在此方法内是为了确保Label1控件已经创建
    _textbmp = _Gettextbitmap(Label1, ADText);
    Label1.BackgroundImageLayout = ImageLayout.None;
    Label1.Text = "";
    Label1.AutoSize = false;
    Label1.Height = _textbmp.Height;
    }
    public Form1()
    {
    Shown += Form1_Shown;
    }
    }
      

  12.   

    补充:
    将以上代码中:
                   BP = new Bitmap(_w + 100, _h);
                    //此处的100为两个首尾相接的字幕间距改成:
                   BP = new Bitmap(_w + (Lb.Width-100), _h);                
    这样可以自适应Label宽度,其中的100可适当调大,此时成为视觉感观的偏移适应量,可自行测试调整
      

  13.   

    楼上的大哥,你的代码不完整,在C#里运行时缺少很多定义如this.CreateGraphics, _tmpBP,
      

  14.   

    完整的吧.由于我不懂C#,用VB.NET写的.直接把代码翻译过来的.我可以直接运行,如果C#中提供少什么的话建议自行添加修改.
      

  15.   


    我做过上下滚动的,原理就是用两个label。楼上这个的方法不错。
      

  16.   

    双缓冲CPU资源占用太多了.同时显示几个字幕还好,多了就不爽了@