最近青岛微软开发者俱乐部 www.qddn.net上有位网友希望得到能改变颜色的进度条,正好我也在做一套.net的通用组件,就把它写出来了,因为比较简单,也没有多少技术含量,就把它帖出来,希望给别的朋友一点帮助

这个进度条控件,除了具有普通进度条的功能以外,还具有如下功能:

设置进度条的背景色和前景色

设置进度条的外观方式(3D,single,none)

是否自动显示当前进度比例(比如在进度条的中间显示当前进度58%)

当然,这个功能还可以增加很多,比如背景色和前景色也可以用图片代替,还有其它的功能打算在以后有时间时再添加,这次就写这些了。

代码如下:

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Drawing.Drawing2D ;

using System.Data;

using System.Windows.Forms;

namespace XiaoPang.Windows

{

/// <summary>

/// GProgressBar 的摘要说明。

/// </summary>

public class GProgressBar : System.Windows.Forms.UserControl

{

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.Container components = null;

public GProgressBar()

{

// 该调用是 Windows.Forms 窗体设计器所必需的。

InitializeComponent();

base.Height = 23 ;

this.Resize+=new EventHandler(GProgressBar_Resize);

this.LocationChanged+=new EventHandler(GProgressBar_Resize);

}

private void GProgressBar_Resize(object sender,System.EventArgs e)

{

base.Refresh() ;

}

private  int mMax =100;

[Browsable(true), Description("最大值"), Category("XiaoPang")]

public int Max

{

get

{

return mMax ;

}

set

{

mMax = value > 0?value:1;

}

}

[Browsable(true), Description("大小"), Category("XiaoPang")]

public new Size Size

{

get

{

return base.Size ;

}

set

{

base.Size = value ;

}

}

private  int mMin =0;

[Browsable(true), Description("最小值"), Category("XiaoPang")]

public int Min

{

get

{

return mMin ;

}

set

{

mMin = value ;

}

}

private int mStep = 1 ;

[Browsable(true), Description("步长"), Category("XiaoPang")]

public int Step

{

get

{

return mStep ;

}

set

{

mStep = value ;

}

}

[Browsable(true), Description("背景色"), Category("XiaoPang")]

public override Color BackColor

{

get

{

return base.BackColor ;

}

set

{

base.BackColor = value ;

}

}

[Browsable(true), Description("前景色"), Category("XiaoPang")]

public override Color ForeColor

{

get

{

return base.ForeColor ;

}

set

{

base.ForeColor = value ;

}

}

private bool mRate = false;

[Browsable(true), Description("是否显示比例数字"), Category("XiaoPang")]

public bool Rate

{

get

{

return mRate ;

}

set

{

mRate = value ;

}

}

private int mValue = 0 ;

[Browsable(true), Description("当前值"), Category("XiaoPang")]

public int Value

{

get

{

return mValue ;

}

set

{

if (value <= this.Max)

mValue = value ;

else

mValue = this.Max ;

this.Refresh() ;

}

}

private BorderStyle mBorderStyle = BorderStyle.Fixed3D ;

[DefaultValue(0), Category("XiaoPang"),Description("外观")]

public BorderStyle BorderStyle

{

get

{

return this.mBorderStyle;

}

set

{

if (this.mBorderStyle != value)

{

this.mBorderStyle = value;

this.Refresh() ;

}

}

}

public void PerformStep()

{

Value++ ;

}

private void DrawProgress(Graphics g,Rectangle rect)

{

int iWidth = (Value*rect.Width)/Max ;

Rectangle DrawRect = new Rectangle(rect.X,rect.Y,iWidth,rect.Height) ;

SolidBrush front = new SolidBrush(this.ForeColor) ;

g.FillRectangle(front,DrawRect);

if (Rate)

{

int iRate = Value*100/Max ;

string strText = iRate.ToString() + "%" ;

int iTextWidth = (int)g.MeasureString(strText,this.Font).Width ;

int iStart = rect.Left + (rect.Width - iTextWidth)/2 ;

Point posS = new Point(iStart -10,rect.Top) ;

Point posE = new Point(iStart + iTextWidth + 10,rect.Bottom) ;

LinearGradientBrush textbrush = new LinearGradientBrush(posS,posE,this.BackColor,this.ForeColor) ;

g.DrawString(strText,this.Font,textbrush,iStart ,rect.Top+5) ;

}

}

protected override void OnPaintBackground(PaintEventArgs pevent)

{

SolidBrush back = new SolidBrush(this.BackColor) ;

pevent.Graphics.FillRectangle(back,pevent.ClipRectangle);

}

protected override void OnPaint(PaintEventArgs e)

{

if (!this.DesignMode)

DrawProgress(e.Graphics,e.ClipRectangle) ;

switch(BorderStyle)

{

case BorderStyle.None:

break ;

case BorderStyle.FixedSingle:

System.Windows.Forms.ControlPaint.DrawBorder3D(e.Graphics,e.ClipRectangle,Border3DStyle.Flat) ;

break ;

case BorderStyle.Fixed3D:

System.Windows.Forms.ControlPaint.DrawBorder3D(e.Graphics,e.ClipRectangle,Border3DStyle.Sunken) ;

break ;

}

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region 组件设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器

/// 修改此方法的内容。

/// </summary>

private void InitializeComponent()

{

//

// GProgressBar

//

this.Name = "GProgressBar";

this.Size = new System.Drawing.Size(150, 24);

}

#endregion

}

}

功能增强的进度条控件(源码)相关推荐

  1. 使用GDI+实现圆形进度条控件的平滑效果

    DownLoad Src 传统的GDI绘制图形时的一个致命缺点是图像存在锯齿毛糙, 使用GDI+能绘制漂亮的渐变图像并有光滑图像的功能.利用GDI+对圆形进度条控件进行修改,效果如下:

  2. DTK进度条控件DWaterProgress

    DTK进度条控件DWaterProgress 简介 用法 注意点 1. 需要调用start来开启UI更新 2. 只显示百分号? 其它 简介 DTK提供了好几种漂亮的进度条控件,我们来看下其中的DWat ...

  3. 【iOS 开发】进度条控件 UIProgressView

    目录 iOS 进度条控件 UIProgressView 1. UIProgressView 常规使用 2. UIProgressView 设置进度图片 附 Github 源码: iOS 进度条控件 U ...

  4. ExtJs4 笔记(8) Ext.slider 滚轴控件、 Ext.ProgressBar 进度条控件、 Ext.Editor 编辑控件...

    本篇要登场的有三个控件,分别是滚轴控件.进度条控件和编辑控件. 一.滚轴控件 Ext.slider 1.滚轴控件的定义 下面我们定义三个具有代表意义滚轴控件,分别展示滚轴横向.纵向,以及单值.多值选择 ...

  5. Android Paint应用之自定义View实现进度条控件

    在上一篇文章<Android神笔之Paint>学习了Paint的基本用法,但是具体的应用我们还没有实践过.从标题中可知,本文是带领读者使用Paint,自定义一个进度条控件. 上图就是本文要 ...

  6. [K/3Cloud]进度条控件编程接口

    进度条控件编程接口 1.启动进度查询 this.GetControl<ProgressBar>().Start(2)  //每2秒查询一次进度 2.汇报进度 在插件中重载 OnQueryP ...

  7. MFC中进度条控件的使用方法

    进度条控件是程序开发中基础控件之一,常用于显示程序的进度.在进行程序安装.文件传输时经常用到.其用法也比较简单固定. 转自:http://jingyan.baidu.com/article/95c9d ...

  8. Android中进度条控件使用

    android中进度条控件使用 ProgressBar pb = findViewById(R.id.pb);pb.setMax(100);pb.setProgress(33); 转载于:https: ...

  9. DevExpress的进度条控件ProgressBarControl的使用-以ZedGraph添加曲线进度为例

    场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...

  10. VC用MFC开发的圆形进度条控件

    DownLoad Src VC用MFC开发的圆形进度条控件 visualsan@yahoo.cn NUAA zss 在NBA2007游戏里,还有很多科幻电影里,经常可以看到圆形进度条.有的用来显示导弹 ...

最新文章

  1. c# 网站在服务器上第一次请求都需要耗时很久,最.net面试题目.doc
  2. Node.js 11.12.0 发布,服务器端的 JavaScript 运行环境
  3. @JsonProperty的使用
  4. Golang的协程(goroutine)和同步机制
  5. ps -ef | grep 查看进程命令
  6. 好程序员HTML5前端教程-css的引入方式和选择器
  7. php node 目录,node.js基于fs模块对系统文件及目录进行读写操作的方法详解
  8. yum配置中driver-class-name: com.mysql.jdbc.Driver报错
  9. java模块化按需加载,JavaScript模块化之使用requireJS按需加载
  10. laravel 获取最后一条sql的小函数
  11. html 苹果 地图,pdrLocationIos0508.html
  12. Android 面试题合集 - 收藏集 - 掘金
  13. 电脑录屏怎么录视频?了解几个小技巧
  14. 基于vue实现sku商品选择
  15. 二维码编码库qrencode
  16. c语言输入1个数字正数负数零的个数,输入n个整数,求输入正数之和,负数之和,并统计相应正数和负数的个数,以输入0表示输入结束....
  17. 自己动手模仿 springmvc 写一个 mvc框架
  18. 手把手教你使用SSM框架实现一个学生管理系统第二章之创建一个web工程及相关配置文件的介绍
  19. android 按钮3d效果图,android.graphics.Camera 实现简单的3D效果
  20. 微信小程序简易朴朴超市

热门文章

  1. html幻灯片效果需要js吗,js 幻灯片的实现
  2. Flutter学习 — 添加Material触摸水波效果
  3. 关于Kendo UI 开发教程
  4. Java 动态代理 Demo
  5. 【DSP开发】解读TI的KeyStone II云技术应用
  6. atitit.项目设计模式---ioc attilax总结v4 q11
  7. ACDSee技巧 - 1
  8. 一个jQuery扩展工具包
  9. windows phone (24) Canvas元素A
  10. 程序员想创业首先要突破自己三关(转)