c#中水晶按钮的程式生成_c#应用

2008-02-23 05:44:16来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

做了一个控件,这样就能够告别图片按钮了:)

效果:

程式源代码:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;

namespace WindowsControlLibrary1
{
/// <summary>
/// UserControl1 的摘要说明。
/// </summary>
public class UserControl1 : Button
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private bool XiaCen=false;
private bool mouseMove=false;
private Color backColor;
public UserControl1()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();

// TODO: 在 InitComponent 调用后添加任何初始化
backColor=this.backColor;
//this.Text=this.ShowFocusCues.ToString();
}

/// <summary>
/// 清理任何正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// UserControl1
//
this.MouseUp = new System.Windows.Forms.MouseEventHandler(this.UserControl1_MouseUp);
this.Paint = new System.Windows.Forms.PaintEventHandler(this.UserControl1_Paint);
this.MouseEnter = new System.EventHandler(this.UserControl1_MouseEnter);
this.KeyUp = new System.Windows.Forms.KeyEventHandler(this.UserControl1_KeyUp);
this.KeyDown = new System.Windows.Forms.KeyEventHandler(this.UserControl1_KeyDown);
this.BackColorChanged = new System.EventHandler(this.UserControl1_BackColorChanged);
this.MouseLeave = new System.EventHandler(this.UserControl1_MouseLeave);
this.MouseDown = new System.Windows.Forms.MouseEventHandler(this.UserControl1_MouseDown);

}
#endregion



protected GraphicsPath GetGraphicsPath(Rectangle rect)
{
GraphicsPath ClientPath = new System.Drawing.Drawing2D.GraphicsPath();
if(rect.Width<=0)
{
rect.Width=1;
}
if(rect.Height<=0)
{
rect.Height=1;
}

ClientPath.AddArc(rect.Left,rect.Top,rect.Height,rect.Height,90f,180f);
ClientPath.AddArc(rect.Right-rect.Height,rect.Top,rect.Height,rect.Height,270f,180f);
ClientPath.CloseFigure();
return ClientPath;
}

protected GraphicsPath GetGraphicsPath1(Rectangle rect)
{
GraphicsPath ClientPath = new System.Drawing.Drawing2D.GraphicsPath();
if(rect.Width<=0)
{
rect.Width=1;
}
if(rect.Height<=0)
{
rect.Height=1;
}

ClientPath.AddArc(rect.Left,rect.Top,rect.Height,rect.Height,190f,80f);
ClientPath.AddArc(rect.Right-rect.Height,rect.Top,rect.Height,rect.Height,270f,80f);
ClientPath.CloseFigure();
return ClientPath;
}

private void DrawYinYing(Graphics gr,bool xiacen)
{
Rectangle rect= this.ClientRectangle;
rect.Inflate(-(rect.Width/10),-(rect.Height)/4);
float bf1=rect.Width/100f;
float bf2=rect.Height/100f;

rect.Y=rect.Y this.ClientRectangle.Height/4;
if(xiacen)
{
rect.Y=rect.Y 4;
}
GraphicsPath path;

for(int a=1;a<33;a )
{
float bf3=bf1*a;
float bf4=bf2*a;
Rectangle rect1=rect;
rect1.Inflate(-(int)bf3,-(int)bf4);
path=GetGraphicsPath(rect1);

int r=backColor.R;
int g=backColor.G;
int b=backColor.B;
r=r 3*a;
g=g 3*a;
b=b 3*a;
if(r>255) r=255;
if(g>255) g=255;
if(b>255) b=255;
gr.FillPath(new SolidBrush(Color.FromArgb(r,g,b)),path);
}
}

private void DrawGaoLiang(Graphics g,bool xiacen)
{
Rectangle rect= this.ClientRectangle;
rect.Inflate(-4,-4);

if(xiacen)
{
rect.Y=rect.Y 4;
}
GraphicsPath path=GetGraphicsPath1(rect);
RectangleF rect1=path.GetBounds();
rect1.Height=rect1.Height 1;
g.FillPath(new LinearGradientBrush(rect1,
Color.FromArgb(0xff,0xff,0xff,0xff),
Color.FromArgb(0xff,backColor),LinearGradientMode.Vertical),path);
}

private void DrawText(Graphics g,bool xiacen)
{
Rectangle rect= this.ClientRectangle;
Rectangle rect1= this.ClientRectangle;
StringFormat stringFormat=new StringFormat();
stringFormat.Alignment=StringAlignment.Center;
stringFormat.LineAlignment=StringAlignment.Center;

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: 数据结构和算法(c#实现)系列-----前言_c#教程

下一篇: 数据结构和算法(c#实现)系列---演示篇(一)_c#教程