Windows mobile 上自定义滚动字幕效果控件
2010-03-10 16:31:00 来源:WEB开发网文章的思路,自己实现的一个ScrollMsg控件,实现字幕的跑马灯滚动效果。贴出来以备以后参考:
代码
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows.Forms;
5 using System.Drawing;
6 namespace XXXX
7 {
8 //自定义滚动信息栏控件
9 class ScrollMsg : PictureBox
10 {
11 const int DEFAULT_INTERVAL = 500;
12 const int MOVE_PACE = 10;
13 //滚动间隔
14 private int m_interval;
15 //定时器
16 private Timer m_timer;
17 //滚动字体
18 private Font m_font;
19 //滚动文本
20 private string m_text;
21 //Graphics
22 private Graphics m_graphics;
23 //记录字体重绘位置
24 private float m_x, m_y;
25 //记录要绘制的字符串的高度和宽度
26 private float m_str_width, m_str_height;
27 private bool m_isDisposed = false;
28 #region 构造函数
29 public ScrollMsg(int interval, string _text)
30 : base()
31 {
32 if (interval <= 0)
33 {
34 throw new ArgumentException("刷新间隔不能小于0毫秒!");
35 }
36 m_interval = interval;
37 m_timer = new Timer();
38 m_timer.Enabled = true;
39 m_timer.Interval = m_interval;
40 m_timer.Tick += new EventHandler(m_timer_Tick);
41 m_text = _text;
42 m_font = new Font("宋体", 13F, FontStyle.Regular);
43 //确定绘制字体初始位置
44 m_x = Width;
45 m_y = 0;
46 m_text = _text;
47 }
48 public ScrollMsg(int interval)
49 : this(interval, string.Empty)
50 {
51 }
52 public ScrollMsg(string text)
53 : this(DEFAULT_INTERVAL, text)
更多精彩
赞助商链接