这个小功能如何实现?[label上的文字从右往左滚动显示]

霜寒月冷 2009-06-06 10:24:16
这个小功能如何实现?[label上的文字从右往左滚动显示]
...全文
903 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmtcl 2010-05-04
  • 打赏
  • 举报
回复
看看完美方案呢
霜寒月冷 2009-06-07
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wartim 的回复:]
引用 9 楼 chz415767975 的回复:
强人,谢谢你的帮忙,我还有个问题.你帮我写的那段程序,在关闭Form窗体.
为什么关不了整个程序.Aplication.Exit() 也关不了
该如何解决此问题.急待解决.thanks!


在关闭窗体事件里必须先调用Stop()停止线程,或者你用线程的后台模式
Thread T = new Thread(new ThreadStart(DoDraw));
T.IsBackground=true;
T.Start();

不过最好是start和stop要对应,否则线程一直在…
[/Quote]
谢谢问题解决了 啊!!
wartim 2009-06-07
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 chz415767975 的回复:]
强人,谢谢你的帮忙,我还有个问题.你帮我写的那段程序,在关闭Form窗体.
为什么关不了整个程序.Aplication.Exit() 也关不了
该如何解决此问题.急待解决.thanks![/Quote]

在关闭窗体事件里必须先调用Stop()停止线程,或者你用线程的后台模式
Thread T = new Thread(new ThreadStart(DoDraw));
T.IsBackground=true;
T.Start();

不过最好是start和stop要对应,否则线程一直在运行,会关不掉的
wzuomin 2009-06-06
  • 打赏
  • 举报
回复
顶 ls 的完美解决方案,呵呵
十八道胡同 2009-06-06
  • 打赏
  • 举报
回复
class Marquee
{
PictureBox PB = new PictureBox();
int X = 0;
String DrawText = String.Empty;
Bitmap OrgBmp = null;
delegate void SetImage(Image NewImage);

public void Start(Form Parent, String Text, Point Location, Size RectSize)
{
this.DrawText = Text;
PB.Parent = Parent;
PB.Location = Location;
PB.Size = RectSize;
X = RectSize.Width;
PB.Visible = true;
PB.Image = new Bitmap(PB.ClientRectangle.Width, PB.ClientRectangle.Height);
Graphics G = Graphics.FromImage(PB.Image);
G.FillRectangle(new SolidBrush(PB.BackColor), PB.ClientRectangle);
G.Dispose();
OrgBmp = new Bitmap(PB.Image);
Thread T = new Thread(new ThreadStart(DoDraw));
T.Start();
}

public void Stop()
{
PB.Visible = false;
}

void DoDraw()
{
while (PB.Visible)
{
Bitmap CacheBmp = new Bitmap(OrgBmp);
Graphics G = Graphics.FromImage(CacheBmp);
G.DrawString(DrawText, new Font("宋体", 10), new SolidBrush(Color.Black),
new PointF(X = X-- < -G.MeasureString(this.DrawText, new Font("宋体", 10)).Width ? PB.Size.Width : X, 0));
G.Dispose();
PB.Invoke(new SetImage(DoSetImage), new Object[] { CacheBmp });
Thread.Sleep(30);
}
}

void DoSetImage(Image NewImage)
{
PB.Image = NewImage;
}
}


up up
wartim 2009-06-06
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsApplication37
{
public partial class Form1 : Form
{
Button B = new Button();
Button B2 = new Button();
Marquee M = null;

public Form1()
{
InitializeComponent();

B.Parent = this;
B.Text = "开始";
B.Click += new EventHandler(B_Click);
B2.Parent = this;
B2.Text = "停止";
B2.Click += new EventHandler(B2_Click);
B2.Location = Point.Add(B.Location, new Size(B.Width, 0));
}

void B_Click(object sender, EventArgs e)
{
M = new Marquee();
M.Start(this, "ABCDEFG", Point.Add(B.Location, new Size(0, B.Height)), new Size(100, 50));
}

void B2_Click(object sender, EventArgs e)
{
M.Stop();
M = null;
}
}

class Marquee
{
PictureBox PB = new PictureBox();
int X = 0;
String DrawText = String.Empty;
Bitmap OrgBmp = null;
delegate void SetImage(Image NewImage);

public void Start(Form Parent, String Text, Point Location, Size RectSize)
{
this.DrawText = Text;
PB.Parent = Parent;
PB.Location = Location;
PB.Size = RectSize;
X = RectSize.Width;
PB.Visible = true;
PB.Image = new Bitmap(PB.ClientRectangle.Width, PB.ClientRectangle.Height);
Graphics G = Graphics.FromImage(PB.Image);
G.FillRectangle(new SolidBrush(PB.BackColor), PB.ClientRectangle);
G.Dispose();
OrgBmp = new Bitmap(PB.Image);
Thread T = new Thread(new ThreadStart(DoDraw));
T.Start();
}

public void Stop()
{
PB.Visible = false;
}

void DoDraw()
{
while (PB.Visible)
{
Bitmap CacheBmp = new Bitmap(OrgBmp);
Graphics G = Graphics.FromImage(CacheBmp);
G.DrawString(DrawText, new Font("宋体", 10), new SolidBrush(Color.Black),
new PointF(X = X-- < -G.MeasureString(this.DrawText, new Font("宋体", 10)).Width ? PB.Size.Width : X, 0));
G.Dispose();
PB.Invoke(new SetImage(DoSetImage), new Object[] { CacheBmp });
Thread.Sleep(30);
}
}

void DoSetImage(Image NewImage)
{
PB.Image = NewImage;
}
}
}
flyingsky00 2009-06-06
  • 打赏
  • 举报
回复
加个Timer控件,
//滚动频率
Timer.Interval=200;
//滚动函数

int txtNum=0;
private void strShow()
{
if ((str.Length - txtNum) > "每次显示字符的个数")
{
label1.Text=str.Substring(txtNum, "每次显示字符的个数"));
txtNum++;
}
else
{
label1.Text=str.Substring(txtNum));
if (txtNum < str.Length)
{
txtNum++;
}
else
{
txtNum = 0;
}
}

}

wangyanboq 2009-06-06
  • 打赏
  • 举报
回复
如果是WebForm,<MARQUEE>滚动文字</MARQUEE>
如果是WinForm,隔一秒刷新一次
Label.Text = " " + Label.Text
刷到没有就再从头开始
yzy8788 2009-06-06
  • 打赏
  • 举报
回复
不知道楼主问的是webform还是winform
霜寒月冷 2009-06-06
  • 打赏
  • 举报
回复
自己up
霜寒月冷 2009-06-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wartim 的回复:]
C# codeusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsApplication37
{
public partial class Form1 : Form
{
Button B = new Button();
Button B2 = new Button();
Marquee M = null;

publi…
[/Quote]
强人,谢谢你的帮忙,我还有个问题.你帮我写的那段程序,在关闭Form窗体.
为什么关不了整个程序.Aplication.Exit() 也关不了
该如何解决此问题.急待解决.thanks!

110,548

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧