中国领先的工业平台

返回贤集网 返回微头条
贤集网技术微头条APP获取

WinForm实现状态栏跑马灯效果的方法示例

 山东大明消毒科技有限公司

下载贤集网APP入驻自媒体

本文实例讲述了WinForm实现状态栏跑马灯效果的方法。分享给大家供大家参考,具体如下:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace WindowsFormsApplication1
  10. {
  11. public partial class Form1 : Form
  12. {
  13. public Form1()
  14. {
  15. InitializeComponent();
  16. }
  17. private Label label = new Label();
  18. public string text = "csdn baihe_591";
  19. private void Form1_Load(object sender, EventArgs e)
  20. {
  21. this.label.Location = new Point(149, 13);
  22. this.label.Size = new Size(134, 16);
  23. this.Controls.Add(label);
  24. this.label.Text = "";
  25. this.timer1.Enabled = true;
  26. this.timer1.Interval = 500;
  27. p = new PointF(this.label.Size.Width, 0);
  28. }
  29. PointF p;
  30. Font f = new Font("宋体", 10);
  31. Color c = Color.White;
  32. string temp;
  33. private void timer1_Tick(object sender, EventArgs e)
  34. {
  35. Graphics g = this.label.CreateGraphics();
  36. SizeF s = new SizeF();
  37. s = g.MeasureString(text, f);//测量文字长度
  38. Brush brush = Brushes.Black;
  39. g.Clear(c);//清除背景
  40. if (temp != text)//文字改变时,重新显示
  41. {
  42. p = new PointF(this.label.Size.Width, 0);
  43. temp = text;
  44. }
  45. else
  46. p = new PointF(p.X - 10, 0);//每次偏移10
  47. if (p.X <= -s.Width)
  48. p = new PointF(this.label.Size.Width, 0);
  49. g.DrawString(text, f, brush, p);
  50. }
  51. }
  52. }
复制代码
最新回复

还没有人回复哦,抢沙发吧~

发布回复

为您推荐

热门交流