本文實(shí)例講述了WinForm實(shí)現(xiàn)狀態(tài)欄跑馬燈效果的方法。分享給大家供大家參考,具體如下:
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 WindowsFormsApplication1{  public partial class Form1 : Form  {    public Form1()    {      InitializeComponent();    }    private Label label = new Label();    public string text = "csdn baihe_591";    private void Form1_Load(object sender, EventArgs e)    {      this.label.Location = new Point(149, 13);      this.label.Size = new Size(134, 16);      this.Controls.Add(label);      this.label.Text = "";      this.timer1.Enabled = true;      this.timer1.Interval = 500;      p = new PointF(this.label.Size.Width, 0);    }    PointF p;    Font f = new Font("宋體", 10);    Color c = Color.White;    string temp;    private void timer1_Tick(object sender, EventArgs e)    {      Graphics g = this.label.CreateGraphics();      SizeF s = new SizeF();      s = g.MeasureString(text, f);//測(cè)量文字長度      Brush brush = Brushes.Black;      g.Clear(c);//清除背景      if (temp != text)//文字改變時(shí),重新顯示      {        p = new PointF(this.label.Size.Width, 0);        temp = text;      }      else        p = new PointF(p.X - 10, 0);//每次偏移10      if (p.X <= -s.Width)        p = new PointF(this.label.Size.Width, 0);      g.DrawString(text, f, brush, p);    }  }}更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《WinForm控件用法總結(jié)》、《C#窗體操作技巧匯總》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#常見控件用法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》
希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。
 
  | 
新聞熱點(diǎn)
疑難解答
圖片精選