欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-11 10:13:52
本文实例讲述了winform实现状态栏跑马灯效果的方法。分享给大家供大家参考,具体如下: using system; using system.collecti...

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

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);//测量文字长度
      brush brush = brushes.black;
      g.clear(c);//清除背景
      if (temp != text)//文字改变时,重新显示
      {
        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);
    }
  }
}

更多关于c#相关内容感兴趣的读者可查看本站专题:《winform控件用法总结》、《c#窗体操作技巧汇总》、《c#数据结构与算法教程》、《c#常见控件用法教程》、《c#面向对象程序设计入门教程》及《c#程序设计之线程使用技巧总结

希望本文所述对大家c#程序设计有所帮助。