using System.Drawing.Drawing2D; protected override void OnPaint( System.Windows.Forms.PaintEventArgs e ) { GraphicsPath oPath = new GraphicsPath(); int x=0; int y=0; int w=Width; int h=Height; int a=40; Graphics g=CreateGraphics(); oPath.AddArc(x,y,a,a,180,90); oPath.AddArc(w-a,y,a,a,270,90); oPath.AddArc(w-a/2,h-a/2,a/2,a/2,0,90); oPath.AddArc(x,h-a,a,a,90,90); oPath.CloseAllFigures(); Region=new Region(oPath); } 这是一个对窗体的外形进行修改的代码。对于Button控件的外形修改方法与之类似。你可以照着改一下~~~只是需要在里边添加对按钮当前状态的判断。
1、采用两张图片替换。一张正常的图片(就像你的地址里的第一个和第二个按钮)、第二张是被按下时的图片(每三个按钮的样式)。
2、对按钮的外形进行重绘。重绘的外形也用上述的两种。
上述两种方法是最常用的方法。它们的区别仅是在表现的方式不同。但处理的方法却是很相似的。你的要求是使得BUTTON拥有Click和UnClick两种状态。(我仅以图片替换的方法为例)当控件的MouseDown发生时,将Button的图片换成被按下时的图片,而MouseUp发生时,换成正常的图片。而默认的图片也将是正常图片。你也可以给自定义的按钮添加另一种状态--MouseEnter和MouseLeave。方法类上。
但我的button属性Flatstyle用了System,使在xp,2003中可以好看些,但这样设置后"图片替换"法似乎无效.
不知"外形重绘"法应该怎样做?
谢谢.
protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
{
GraphicsPath oPath = new GraphicsPath();
int x=0;
int y=0;
int w=Width;
int h=Height;
int a=40;
Graphics g=CreateGraphics();
oPath.AddArc(x,y,a,a,180,90);
oPath.AddArc(w-a,y,a,a,270,90);
oPath.AddArc(w-a/2,h-a/2,a/2,a/2,0,90);
oPath.AddArc(x,h-a,a,a,90,90);
oPath.CloseAllFigures();
Region=new Region(oPath);
}
这是一个对窗体的外形进行修改的代码。对于Button控件的外形修改方法与之类似。你可以照着改一下~~~只是需要在里边添加对按钮当前状态的判断。