C#文字滚动

askjhx 2009-06-09 10:26:00
做项目的时候 我想用一个lable控件作出一个从左向右的滚动效果,当它到了最左边的时候又会自动的回到右边 然后就是一直的滚动 从右边到左边一直循环这滚动 请问一下 我该怎么样去做它
还忘各位不吝赐教.... 谢谢了 (最好能给点代码的提示)
...全文
1097 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lqliang125 2011-09-28
  • 打赏
  • 举报
回复
label1.Left = label1.Left - 2;
if (label1.Right < 0)
{
label1.Left = this.Width;
}
wgqtiytbgdgh 2011-07-13
  • 打赏
  • 举报
回复
LBG.Text = LBG.Text.Substring(1) + LBG.Text[0];
这个是最好用的
LBG是标签
不明白的找我
还有啊,别忘记TMG.Stop();启动记时器
ye_jw 2011-05-17
  • 打赏
  • 举报
回复
抱歉了,一楼的是可以的,实现的是字体向左向右移动的

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}


private void Form1_Load(object sender, EventArgs e)

{

this.timer1.Interval = 1;

this.timer1.Enabled = true;

//this.WindowState = FormWindowState.Maximized;

}

bool i = true;

int xPox;

private void timer1_Tick(object sender, EventArgs e)

{

this.label1.Location = new Point(xPox, this.label1.Location.Y);

if (xPox > this.Width - this.label1.Size.Width+label1.Width)//字幕到了最右边
i = false;

if (xPox < 0-label1.Width)//字幕到了最左边

i = true;

if (i)

xPox+=5;//右走

else

xPox-=5;//左走


}

private void label1_Click(object sender, EventArgs e)

{

this.Close();

}

}
ye_jw 2011-05-17
  • 打赏
  • 举报
回复
一楼的似乎实现不了的……
试试这个:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 欢迎条
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Interval = 10;
this.timer1.Enabled = true;
//this.WindowState = FormWindowState.Maximized;
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Left = label1.Left - 2;
if (label1.Right<0)
{
label1.Left = this.Width;
}
}

private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
zhuxishanren 2011-04-30
  • 打赏
  • 举报
回复
我得在这好好学学。
松林迷途 2009-06-17
  • 打赏
  • 举报
回复
路过 学知识来了。
zhouxingyu896 2009-06-10
  • 打赏
  • 举报
回复
支持1楼的

十八道胡同 2009-06-09
  • 打赏
  • 举报
回复
bool ist = true;//为true时字幕向右走,反之向左走
private void timer1_Tick(object sender, EventArgs e)
{
this.label1.Location = new Point(xPox,this.label1.Location.Y);

if (xPox == this.Width-this.label1.Size.Width)//字幕到了最右边
ist = false;
if(xPox==0)//字幕到了最左边
ist = true;
if (ist)
xPox++;//右走
else
xPox--;//左走
}
十八道胡同 2009-06-09
  • 打赏
  • 举报
回复
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;
}
}
}
askjhx 2009-06-09
  • 打赏
  • 举报
回复
一楼的 写错了 不好意思.... 是一楼的那段源代码...
askjhx 2009-06-09
  • 打赏
  • 举报
回复
二楼的 你的代码 很不错 我要的就是这样的 但是我看了半天没能看懂.... 如果可以的话 希望你帮帮写点注释 好不好

还有 我想让它只从右往左 不要让它在左边 就直接被弹了回来到右边 希望你能加点注释让我能好理解点 谢谢了
wuyq11 2009-06-09
  • 打赏
  • 举报
回复
wartim 2009-06-09
  • 打赏
  • 举报
回复
这个小功能如何实现?[label上的文字从右往左滚动显示]
http://topic.csdn.net/u/20090606/10/5fc58b85-d448-4449-a46e-feb3fd9b0bcc.html

你稍微改一下就行了

修改一下昵称 2009-06-09
  • 打赏
  • 举报
回复

private void Form1_Load(object sender, EventArgs e)
{
this.label1.Location = new Point(0, 0);
}
int xPox = 0;
bool ist = true;
private void timer1_Tick(object sender, EventArgs e)
{
this.label1.Location = new Point(xPox,this.label1.Location.Y);

if (xPox == this.Width-this.label1.Size.Width)
ist = false;
if(xPox==0)
ist = true;
if (ist)
xPox++;
else
xPox--;
}

110,538

社区成员

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

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

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