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
}
}
新闻热点
疑难解答