单行屏幕怎么实现内容上下滚动
经常路过房产中介,看到他们门的上边放着一个单行显示的显示屏,不停的上下滚动着,怎么实现的呀?自己简单做了个,主要是画一个矩形,再定时移动它的Y坐标。不过,感觉貌似这样隐隐存在隐患:如果行数特别多,就需要每次的定量移动特别的精确,不然多了就会不整齐了。于是,想到另外一个方法:把要显示的字符串内容按屏幕宽度拆分成固定长度的字符串数组,然后依次的来显示在单行的显示屏上。可又不知道如何来按固定长度拆分str?请教高手支招!谢谢!
程序代码:using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 单行显示屏
{
public partial class Form1 : Form
{
string str = "LED可以给国家和使用者节省大量电能,给承做方节省大量工时。LED应用技术的发展,给竞争激烈的广告业增添了新的活力。其独有的、不同的发光形势、被广泛的应用在广告产品的制作领域。不同规格的LED有着不同的发光角度和不同的亮度。";
PointF pf = new PointF(10, 2);
Font f = new Font("宋体", 15);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Start();
}
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Stop();
}
private void timer1_Tick(object sender, EventArgs e)
{
Brush brush = Brushes.Red;
Graphics g = pictureBox1.CreateGraphics();
g.Clear(Color.White);
SizeF s = new SizeF();
s = g.MeasureString(str, f,524);
RectangleF k = new RectangleF(pf, s);
g.DrawString(str, f, brush, k);
if (pf.Y >= pictureBox1.Height - s.Height)
{
pf = new PointF(pf.X, pf.Y - (float)22.8);
}
else
{
pf = new PointF(5, 2);
}
}
}
}








