/// <summary> /// Description of MainForm. /// </summary> public partial class MainForm : Form { protected int paintX=0; protected Size vSize; protected string rollingMsg="Testing rolling message..."; protected Timer rollingTimer;
public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent();
lbl_Status.Paint+= new PaintEventHandler(lbl_Status_Paint); vSize=TextRenderer.MeasureText(rollingMsg,lbl_Status.Font);
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
protected int paintX=0;
protected Size vSize;
protected string rollingMsg="Testing rolling message...";
protected Timer rollingTimer;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
lbl_Status.Paint+= new PaintEventHandler(lbl_Status_Paint);
vSize=TextRenderer.MeasureText(rollingMsg,lbl_Status.Font);
rollingTimer=new Timer();
rollingTimer.Interval=10;
rollingTimer.Enabled=true;
rollingTimer.Tick+= new EventHandler(rollingTimer_Tick);
} void lbl_Status_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString(rollingMsg,lbl_Status.Font,Brushes.Black,new PointF((float)paintX,0f));
} void rollingTimer_Tick(object sender, EventArgs e)
{
ToRollMsg();
}
protected void ToRollMsg()
{
if((paintX+vSize.Width)<0)
{
paintX=lbl_Status.Width;
}
paintX--;
lbl_Status.Invalidate();
}
}
这里lbl_Status是StatusBar上面的ToolStripStatusLabel