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

本文实例讲述了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#程序设计有所帮助。

(0)

相关推荐

  • C# WinForm实现Win7 Aero透明效果代码

    在Vista系统之后,微软为窗体程序提供了Aero磨砂的效果,如下图.那么用C#如何来实现这种磨砂效果呢? 背景为我的桌面 那先上代码吧: [StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int Left; public int Right; public int Top; public int Bottom; } [DllImport("dwmapi.dll", PreserveSig = fa

  • WinForm实现窗体最大化并遮盖任务栏的方法

    本文实例讲述了WinForm实现窗体最大化并遮盖任务栏的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Windows.Forms; using System.Drawing; namespace CSImageFullScreenSlideShow { public class FullScreen { private FormWindowState winState; private FormBorderStyle brdStyle; p

  • Winform窗体效果实例分析

    本文实例分析了Winform窗体效果.分享给大家供大家参考.具体如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication4 { public partial cl

  • C#实现winform渐变效果的方法

    本文实例实现一个启动画面,采用了显示Aform,过一段时间,隐藏这个Aform,showdialog下一个Bform,closeAForm这个方法来做了,不知道大家有没有更好的办法. 设定程序从Aform启动: 复制代码 代码如下: static void Main()  {    Application.EnableVisualStyles();    Application.SetCompatibleTextRenderingDefault(false);    Application.Ru

  • WinForm实现自定义右下角提示效果的方法

    本文实例讲述了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 IcoFl

  • WinForm实现同时让两个窗体有激活效果的特效实例

    本文实例讲述了WinForm实现同时让两个窗体有激活效果的特效.主要采用windows api实现一个窗体激活的时候给另外一个发消息.分享给大家供大家参考. 具体实现方法如下: using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsApplication43 { public partial class Form1 : Form { Form frm =nu

  • C#实现WinForm禁止最大化、最小化、双击标题栏、双击图标等操作的方法

    本文实例讲述了C#实现WinForm禁止最大化.最小化.双击标题栏.双击图标等操作的方法.分享给大家供大家参考.具体实现方法如下: protected override void WndProc(ref Message m) { if (m.Msg==0x112) { switch ((int) m.WParam) { //禁止双击标题栏关闭窗体 case 0xF063: case 0xF093: m.WParam = IntPtr.Zero; break; //禁止拖拽标题栏还原窗体 case

  • winform下实现win7 Aero磨砂效果实现代码

    效果图: 复制代码 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.ServiceModel; using System.Runtime.InteropServices; name

  • 用 C# Winform做出全透明的磨砂玻璃窗体效果代码

    首先, 调用系统 API, 这里如果要引用神马的, 就不一一列出了, 大家自己引用一下. 复制代码 代码如下: [StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int Left; public int Right; public int Top; public int Bottom; } [DllImport("dwmapi.dll", PreserveSig = false)] public s

  • WinForm实现仿视频播放器左下角滚动新闻效果的方法

    本文实例讲述了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; using Syst

  • Winform实现鼠标可穿透的窗体镂空效果

    今天找到一个名叫LICEcap的录屏软件,录制界面是这样的: 这个炫酷的空心窗口就是镜头,调整好大小,然后对准需要录制的地方按下Record就可以生成gif了. 卧槽太NB了我也要做一个! 根据StackOverflow站的提示(在这里),我们需要使用一个在Windows2000及之后平台可用的,用以实现不规则窗体的分层窗口API (SetLayerWindowAttributes).根据百度我们先需要使用一个名为SetWindowLong的Win32 API来把窗体设定为分层窗体. 为了在.N

随机推荐