java 水晶按钮_C#中水晶按钮的程序生成
做了一个控件,这样就可以告别图片按钮了:)
程序源代码:
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
{
///
/// UserControl1 的摘要说明。
///
public class UserControl1 : Button
{
///
/// 必需的设计器变量。
///
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();
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///
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;
rect.Y=this.ClientRectangle.Height/5;
if(xiacen)
{
rect.Y=rect.Y+4;
rect1.Y=rect1.Y+4;
}
Font font=this.Font;
if(mouseMove)
{
font=new Font(this.Font,FontStyle.Underline);
}
g.DrawString(this.Text,font,
new SolidBrush(Color.FromArgb(0x66,backColor)),rect,stringFormat);
g.DrawString(this.Text,font,new SolidBrush(this.ForeColor),rect1,stringFormat);
}
private void UserControl1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(XiaCen==false)
{
XiaCen=true;
this.Refresh();
}
}
private void UserControl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(XiaCen==true)
{
XiaCen=false;
this.Refresh();
}
}
private void UserControl1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(new SolidBrush(backColor),0,0,this.Width,this.Height);
e.Graphics.SmoothingMode=SmoothingMode.HighQuality;
e.Graphics.TextRenderingHint=TextRenderingHint.AntiAliasGridFit;
Rectangle rect=new Rectangle(0,0,this.Width,this.Height);
GraphicsPath ClientPath=GetGraphicsPath(rect);
e.Graphics.FillPath(new SolidBrush(backColor),ClientPath);
this.Region=new System.Drawing.Region(ClientPath);
DrawYinYing(e.Graphics,XiaCen);
DrawGaoLiang(e.Graphics,XiaCen);
DrawText(e.Graphics,XiaCen);
if(this.Focused)
{
e.Graphics.DrawPath(new Pen(Color.FromArgb(0x22,0xff,0xff,0xff), 3), ClientPath);
}
}
private void UserControl1_BackColorChanged(object sender, System.EventArgs e)
{
int r=BackColor.R;
int g=BackColor.G;
int b=BackColor.B;
r=r+0x22;
g=g+0x22;
b=b+0x22;
if(r>255) r=255;
if(g>255) g=255;
if(b>255) b=255;
backColor=Color.FromArgb(r,g,b);
}
private void UserControl1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(XiaCen==false && e.KeyCode==Keys.Space)
{
XiaCen=true;
this.Refresh();
}
}
private void UserControl1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(XiaCen==true && e.KeyCode==Keys.Space)
{
XiaCen=false;
this.Refresh();
}
}
private void UserControl1_MouseEnter(object sender, System.EventArgs e)
{
if(mouseMove==false)
{
mouseMove=true;
this.Refresh();
}
}
private void UserControl1_MouseLeave(object sender, System.EventArgs e)
{
if(mouseMove==true)
{
mouseMove=false;
this.Refresh();
}
}
}
}
java 水晶按钮_C#中水晶按钮的程序生成相关推荐
- php重置网页按钮,html中递交按钮和重置按钮代码,要怎么输入?
1.加一个html标签就可以了 ,这个就是了,复制可以了,value设置为空就可以了. 2.合理的运用图片,能够使站点更加丰富多彩,相信有许多喜欢用图片的设计师都遇到过一个问题:用图片实现表单(for ...
- java attributes用法_C#中的Attributes的用法
今天研究了一下C#中的Attributes的用法,感觉很有用,现总结以下: 在前台用JS写的脚本方法,除了可以直接用在前台控件的属性中,还可以在后台运用. 即在后台页面加载时,调用JS方法.语法格式有 ...
- java 挥发注解_C中的挥发性预选赛
java 挥发注解 什么是C中的限定词? (What is Qualifiers in C?) Qualifiers in C are the keywords which are used to m ...
- java 指针 引用_C++中的指针和引用与Java中的引用区别
C++的指针和Java中的引用比较像,在作为函数参数传递时,都可以在函数内部改变 "外部" 的值 C++的引用使用时必须是初始化的,他是一段内存的别名,因此也可以在函数内部改变&q ...
- java cps变换_C#中的递归APS和CPS模式详解
累加器传递模式(Accumulator passing style) 尾递归优化在于使堆栈可以不用保存上一次的返回地址/状态值,从而把递归函数当成一个普通的函数调用. 递归实际上是依赖上次的值,去求下 ...
- java 分部类_C#中分部类和分部方法的应用
分部类(Partial Class)在C#2.0引入,分部方法(Partial Method)在C#3.0引入,这两个语法特性都具有相同的特性:将类(或)方法的代码分散在多个地方. 1.分部类的特性和 ...
- java添加按钮点击事件_如何为odoo 10中的按钮点击事件添加一个java脚本处理程序?...
我想使用java脚本为header中的按钮创建一个处理程序.下面我视图模型给出:如何为odoo 10中的按钮点击事件添加一个java脚本处理程序? inherit_id="web.asset ...
- java jtable 按钮_java web 怎么在jtable中添加按钮?
展开全部 java web在jtable中添加按钮的示例如下:import java.awt.BorderLayout; import java.awt.Color; import java.awt. ...
- java swt 画按钮_向表中添加按钮(java swt)
我正在尝试复制类似于此的UI: 我一直在关注如何创建表格每列中的按钮的作者说明(没有成功).我的项目与他的区别在于我正在尝试使用Tree而不是Table,而我正在使用eclipse TreeViewe ...
- eclipse java shell 窗体显示 bat运行不显示_java eclipse中如何实现点击主窗口sShell中的按钮打开另外一个子窗口sShell...
java eclipse中如何实现点击主窗口sShell中的按钮打开另外一个子窗口sShell 关注:97 答案:2 mip版 解决时间 2021-01-31 13:01 提问者╬═掵中注定 20 ...
最新文章
- SpringMVC,针对不支持PUT、DELETE提交的游览器处理方式
- 查看Linux 硬件配置
- linux哪些分区用固态硬盘,关于linux:简单聊聊固态硬盘的物理结构
- linux命令端口探测
- encode,decode
- Asp.Net 将HTML中通过dom-to-image.js标签div内的内容转化为图片保存到本地
- codeforce A - Sequence with Digits
- MobaXterm——Portable edition迁移账号信息等到新的版本解决方案
- python中s和t是两个集合、对s|t描述正确的是_全国计算机等级考试二级教程--python语言程序设计(2018年版)第六章:组合数据类型...
- Spark2.x RPC解析
- 头条自己提问的问题在哪看_在头条的这三十天
- 我的世界服务器拔刀修复,我的世界拔刀剑怎么修复
- 【手写数字识别】基于matlab CNN网络手写数字识别分类【含Matlab源码 1286期】
- 计算机控制系统与常规仪表控制系统的主要异同点,计算机控制统考试.doc
- MATLAB算术均值滤波器
- [翻译]IAdaptable是什么?
- poj 4105 拯救公主(bfs+二进制状态压缩)
- uni-app跨平台开发app,用Hbuilderx打包安卓应用程序到上架google play 完成l流程
- 干货!Labeling Trick: 一个图神经网络多节点表示学习理论
- mono for andriod 自动提示输入控件AutoCompleteTextView