样例的代码。
1: // 功能:
2: // 描述:
3: // 编码:温伟鹏
4: // 日期:12/17/2008 14:04:12
5:
6: using System;
7: using System.Collections.Generic;
8: using System.ComponentModel;
9: using System.Data;
10: using System.Drawing;
11: using System.Text;
12: using System.Windows.Forms;
13: using System.Threading;
14:
15: namespace UITest
16: {
17: public partial class Form2 : Form
18: {
19: private BackgroundWorker timer;
20:
21: public Form2()
22: {
23: InitializeComponent();
24:
25: timer = new BackgroundWorker();
26: timer.WorkerReportsProgress = true;
27: timer.DoWork += new DoWorkEventHandler(timer_DoWork);
28:
29: timer.RunWorkerAsync();
30: }
31:
32: void timer_DoWork(object sender, DoWorkEventArgs e)
33: {
34: RunProgress();
35: }
36:
37: private void RunProgress()
38: {
39: for (int i = 1; i <= this.progressBar1.Maximum; i++)
40: {
41: this.progressBar1.Value = i;
42: this.standardProgressBar1.Value = i;
43:
44: Thread.Sleep(10);
45:
46: if (i == this.progressBar1.Maximum)
47: {
48: RunProgress();
49: }
50: }
51: }
52: }
53: }
1: namespace UITest
2: {
3: partial class Form2
4: {
5: /// <summary>
6: /// 必需的设计器变量。
7: /// </summary>
8: private System.ComponentModel.IContainer components = null;
9:
10: /// <summary>
11: /// 清理所有正在使用的资源。
12: /// </summary>
13: /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14: protected override void Dispose(bool disposing)
15: {
16: if (disposing && (components != null))
17: {
18: components.Dispose();
19: }
20: base.Dispose(disposing);
21: }
22:
23: #region Windows 窗体设计器生成的代码
24:
25: /// <summary>
26: /// 设计器支持所需的方法 - 不要
27: /// 使用代码编辑器修改此方法的内容。
28: /// </summary>
29: private void InitializeComponent()
30: {
31: this.progressBar1 = new Esint.UI.WinFormUI.ProgressBar();
32: this.standardProgressBar1 = new Esint.UI.WinFormUI.StandardProgressBar();
33: this.SuspendLayout();
34: //
35: // progressBar1
36: //
37: this.progressBar1.BarBlockSize = 10;
38: this.progressBar1.ForeColor = System.Drawing.Color.White;
39: this.progressBar1.Location = new System.Drawing.Point(71, 12);
40: this.progressBar1.Maximum = 1000F;
41: this.progressBar1.Minimum = 0F;
42: this.progressBar1.MinimumSize = new System.Drawing.Size(131, 80);
43: this.progressBar1.Name = "progressBar1";
44: this.progressBar1.Orientation = System.Windows.Forms.Orientation.Horizontal;
45: this.progressBar1.Shadow = null;
46: this.progressBar1.ShowShadow = false;
47: this.progressBar1.Size = new System.Drawing.Size(537, 83);
48: this.progressBar1.TabIndex = 0;
49: //
50: // standardProgressBar1
51: //
52: this.standardProgressBar1.Location = new System.Drawing.Point(71, 138);
53: this.standardProgressBar1.Maximum = 1000F;
54: this.standardProgressBar1.MinimumSize = new System.Drawing.Size(200, 17);
55: this.standardProgressBar1.Name = "standardProgressBar1";
56: this.standardProgressBar1.Orientation = System.Windows.Forms.Orientation.Horizontal;
57: this.standardProgressBar1.Shadow = null;
58: this.standardProgressBar1.ShowShadow = false;
59: this.standardProgressBar1.Size = new System.Drawing.Size(537, 20);
60: this.standardProgressBar1.TabIndex = 1;
61: this.standardProgressBar1.Text = "standardProgressBar2";
62: //
63: // Form2
64: //
65: this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
66: this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
67: this.BackColor = System.Drawing.SystemColors.WindowFrame;
68: this.ClientSize = new System.Drawing.Size(682, 189);
69: this.Controls.Add(this.standardProgressBar1);
70: this.Controls.Add(this.progressBar1);
71: this.Name = "Form2";
72: this.Text = "Form2";
73: this.ResumeLayout(false);
74:
75: }
76:
77: #endregion
78:
79: private Esint.UI.WinFormUI.ProgressBar progressBar1;
80: private Esint.UI.WinFormUI.StandardProgressBar standardProgressBar1;
81: }
82: }
DrawHelper的创建圆角矩形函数
1: /// <summary>
2: /// 创建圆角矩形
3: /// </summary>
4: /// <param name="rectangle">圆角矩形的边界矩形</param>
5: /// <param name="radius">圆角大小</param>
6: /// <returns>返回圆角矩形的路径</returns>
7: public static GraphicsPath CreateRoundRectangle(Rectangle rectangle, int radius)
8: {
9: GraphicsPath path = new GraphicsPath(FillMode.Winding);
10: int l = rectangle.Left;
11: int t = rectangle.Top;
12: int w = rectangle.Width;
13: int h = rectangle.Height;
14: int d = radius << 1;
15: path.AddArc(l, t, d, d, 180, 90); // topleft
16: path.AddArc(l + w - d, t, d, d, 270, 90); // topright
17: path.AddArc(l + w - d, t + h - d, d, d, 0, 90); // bottomright
18: path.AddArc(l, t + h - d, d, d, 90, 90); // bottomleft
19: path.CloseFigure();
20: return path;
21: }
Margin的Converter类:
1: // 功能:Margin的类型转换器
2: // 描述:
3: // 编码:温伟鹏
4: // 日期:12/12/2008 13:21:21
5:
6: using System;
7: using System.Collections.Generic;
8: using System.Text;
9: using System.ComponentModel;
10: using System.Reflection;
11: using System.ComponentModel.Design.Serialization;
12:
13: namespace Esint.UI.WinFormUI
14: {
15: /// <summary>
16: /// Margin的类型转换器
17: /// </summary>
18: public class MarginConverter:TypeConverter
19: {
20: /// <summary>
21: /// 返回该转换器是否可以使用指定的上下文将给定类型的对象转换为此转换器的类型。
22: /// </summary>
23: /// <param name="context">System.ComponentModel.ITypeDescriptorContext,提供格式上下文。</param>
24: /// <param name="sourceType">一个 System.Type,表示要转换的类型。</param>
25: /// <returns>如果该转换器能够执行转换,则为 true;否则为 false。</returns>
26: public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
27: {
28: if (sourceType == typeof(String))
29: {
30: return true;
31: }
32:
33: return base.CanConvertFrom(context, sourceType);
34: }
35: /// <summary>
36: /// 返回此转换器是否可以使用指定的上下文将该对象转换为指定的类型。
37: /// </summary>
38: /// <param name="context">System.ComponentModel.ITypeDescriptorContext,提供格式上下文。</param>
39: /// <param name="destinationType">一个 System.Type,表示要转换到的类型。</param>
40: /// <returns>如果该转换器能够执行转换,则为 true;否则为 false。</returns>
41: public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
42: {
43: if (destinationType == typeof(String))
44: return true;
45:
46: if (destinationType == typeof(InstanceDescriptor))
47: return true;
48:
49: return base.CanConvertTo(context, destinationType);
50: }
51: /// <summary>
52: /// 使用指定的上下文和区域性信息将给定的值对象转换为指定的类型。
53: /// </summary>
54: /// <param name="context">System.ComponentModel.ITypeDescriptorContext,提供格式上下文。</param>
55: /// <param name="culture">System.Globalization.CultureInfo。如果传递 null,则采用当前区域性。</param>
56: /// <param name="value">要转换的 System.Object。</param>
57: /// <param name="destinationType">value 参数要转换成的 System.Type。</param>
58: /// <returns>表示转换的 value 的 System.Object。</returns>
59: /// <exception cref="System.ArgumentNullException">
60: /// destinationType 参数为 null。
61: /// </exception>
62: /// <exception cref="System.NotSupportedException">
63: /// 不能执行转换。
64: /// </exception>
65: public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
66: {
67: String result = "";
68: if (destinationType == typeof(String))
69: {
70: Margin margin = (Margin)value;
71: result = string.Format("{0},{1}", margin.Top.ToString(),margin.Left.ToString());
72: return result;
73:
74: }
75:
76: if (destinationType == typeof(InstanceDescriptor))
77: {
78: ConstructorInfo ci = typeof(Margin).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) });
79: Margin margin = (Margin)value;
80: return new InstanceDescriptor(ci, new object[] { margin.Top,margin.Left,margin.Bottom,margin.Right});
81: }
82:
83: return base.ConvertTo(context, culture, value, destinationType);
84: }
85: /// <summary>
86: /// 使用指定的上下文和区域性信息将给定的对象转换为此转换器的类型。
87: /// </summary>
88: /// <param name="context">System.ComponentModel.ITypeDescriptorContext,提供格式上下文。</param>
89: /// <param name="culture">用作当前区域性的 System.Globalization.CultureInfo。</param>
90: /// <param name="value">要转换的 System.Object。</param>
91: /// <returns>表示转换的 value 的 System.Object。</returns>
92: /// <exception cref="System.NotSupportedException">
93: /// 不能执行转换。
94: /// </exception>
95: public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
96: {
97: if (value is string)
98: {
99: string[] result = ((String)value).Split(',');
100: if (result.Length <= 0 && (result.Length!=2 || result.Length!=4))
101: {
102: throw new ArgumentException("输入值的格式不正确!");
103: }
104:
105: Margin margin = new Margin();
106: margin.Top = Convert.ToInt32(result[0]);
107: margin.Left = Convert.ToInt32(result[1]);
108: if (result.Length == 4)
109: {
110: margin.Bottom = Convert.ToInt32(result[2]);
111: margin.Right = Convert.ToInt32(result[3]);
112: }
113: else
114: {
115: margin.Right = margin.Left;
116: margin.Bottom = margin.Top;
117: }
118: return margin;
119: }
120:
121: return base.ConvertFrom(context, culture, value);
122: }
123: /// <summary>
124: /// 使用指定的上下文返回该对象是否支持属性 (Property)。
125: /// </summary>
126: /// <param name="context">
127: /// System.ComponentModel.ITypeDescriptorContext,提供格式上下文。
128: /// </param>
129: /// <returns>
130: /// 如果应调用 System.ComponentModel.TypeConverter.GetProperties(System.Object) 来查找此对象的属性,则为true;否则为 false。
131: /// </returns>
132: public override bool GetPropertiesSupported(ITypeDescriptorContext context)
133: {
134: return true;
135: }
136: /// <summary>
137: /// 使用指定的上下文返回值参数指定的数组类型的属性 (Property) 的集合。
138: /// </summary>
139: /// <param name="context">
140: /// System.ComponentModel.ITypeDescriptorContext,提供格式上下文。
141: /// </param>
142: /// <param name="value">
143: /// 一个 System.Object,指定要为其获取属性的数组类型。
144: /// </param>
145: /// <param name="attributes">
146: /// 用作筛选器的 System.Attribute 类型数组。
147: /// </param>
148: /// <returns>
149: /// 具有为此数据类型公开的属性的 System.ComponentModel.PropertyDescriptorCollection;或者如果没有属性,则为null.
150: /// </returns>
151: public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
152: {
153: return TypeDescriptor.GetProperties(typeof(Margin), attributes);
154: }
155: }
156: }