圆形、椭圆形 按钮控件的制作
2009-06-11 00:56
459 查看
这个 也是朋友经常问我的,我也经常遇见的。就是 一个 非方形的按钮,即圆形、椭圆形按钮控件
首先它的制作过程是:新建一个 windows 窗体控件库,然后将 UserControl1.cs这个文件删除。
在 项目 添加新项 选择组件库 并命名为 EllipseButton.cs 。在EllipseButton.Designer.cs里添加2个事件
分别为 该控件的长度和文本改变 事件。 并添加头文件
using System.Windows.Forms;
using System.Drawing.Drawing2D;
Code
////吧Component修改为继承System.Windows.Forms.Button
public partial class EllipseButton : System.Windows.Forms.Button
{
private Color startColor=Color.Blue;
// private Color costartColor=Color.White;
private Color endColor = Color.GreenYellow;
[Description("设定渐变的起始色"),Category("Appearance")]//注视
public Color StartColor
{
get
{ return startColor;
}
set
{
startColor=value;
RePaint();
}
}
[Description("设定渐变的终止色"), Category("Appearance")]
public Color EndColor
{
get
{
return endColor;
}
set
{
endColor = value;
RePaint();
}
}
public EllipseButton()
{
InitializeComponent();
this.Width = 100;
this.Height = 100;
}
//绘制圆形区域
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics g = pe.Graphics;
g.Clear(this.BackColor);
Rectangle rect = new Rectangle(0,0,this.Width,this.Height);
LinearGradientBrush myBrush = new LinearGradientBrush(rect,startColor,endColor,LinearGradientMode.ForwardDiagonal);
g.FillEllipse(myBrush, rect);
myBrush.Dispose();
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
g.DrawString(this.Text, Font, new SolidBrush(this.ForeColor), rect, format);
}
//重新绘制圆形区域
private void RePaint()
{
Rectangle rect=new Rectangle(0,0,this.Width,this.Height);
OnPaint(new PaintEventArgs(this.CreateGraphics(), rect));
}
private void EllipseButton_Resize(object sender, System.EventArgs e)
{
RePaint();
}
private void EllipseButton_TextChanged(object sender, System.EventArgs e)
{
RePaint();
}
}
作者:FreeComputer
首先它的制作过程是:新建一个 windows 窗体控件库,然后将 UserControl1.cs这个文件删除。
在 项目 添加新项 选择组件库 并命名为 EllipseButton.cs 。在EllipseButton.Designer.cs里添加2个事件
分别为 该控件的长度和文本改变 事件。 并添加头文件
using System.Windows.Forms;
using System.Drawing.Drawing2D;
Code
////吧Component修改为继承System.Windows.Forms.Button
public partial class EllipseButton : System.Windows.Forms.Button
{
private Color startColor=Color.Blue;
// private Color costartColor=Color.White;
private Color endColor = Color.GreenYellow;
[Description("设定渐变的起始色"),Category("Appearance")]//注视
public Color StartColor
{
get
{ return startColor;
}
set
{
startColor=value;
RePaint();
}
}
[Description("设定渐变的终止色"), Category("Appearance")]
public Color EndColor
{
get
{
return endColor;
}
set
{
endColor = value;
RePaint();
}
}
public EllipseButton()
{
InitializeComponent();
this.Width = 100;
this.Height = 100;
}
//绘制圆形区域
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics g = pe.Graphics;
g.Clear(this.BackColor);
Rectangle rect = new Rectangle(0,0,this.Width,this.Height);
LinearGradientBrush myBrush = new LinearGradientBrush(rect,startColor,endColor,LinearGradientMode.ForwardDiagonal);
g.FillEllipse(myBrush, rect);
myBrush.Dispose();
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
g.DrawString(this.Text, Font, new SolidBrush(this.ForeColor), rect, format);
}
//重新绘制圆形区域
private void RePaint()
{
Rectangle rect=new Rectangle(0,0,this.Width,this.Height);
OnPaint(new PaintEventArgs(this.CreateGraphics(), rect));
}
private void EllipseButton_Resize(object sender, System.EventArgs e)
{
RePaint();
}
private void EllipseButton_TextChanged(object sender, System.EventArgs e)
{
RePaint();
}
}
作者:FreeComputer
相关文章推荐
- android开源项目---RoundedImageView制作圆角矩形,椭圆形以其圆形控件
- silverlight 如何编辑控件模板?以制作圆形按钮为例
- 如何制作一个圆形的按钮
- 利用.NET绘图技术制作水晶按钮控件(转)
- 利用.NET绘图技术制作水晶按钮控件
- 自定义按钮控件-圆形按钮
- 利用.Net绘图技术制作水晶按钮控件
- 在vc MFC下制作具有XP风格按钮等控件
- 圆形热点按钮的制作
- iOS小项目中的一些小拾遗(关于UIColor颜色以及UIButton制作圆形按钮)
- 使用RecyclerView制作包含左滑删除按钮的列表控件
- [原译]一步步教你制作WPF圆形玻璃按钮
- 利用:before和:after伪类制作CSS3 圆形按钮 含demo
- Android使用shape制作圆形控件及添加弹跳动画
- Android使用shape制作圆形控件及添加弹跳动画
- VC控件编程-制作弹出式菜单按钮
- Android使用shape制作圆形控件及添加弹跳动画
- 制作圆形Swing按钮(中文版)
- 纯css制作三角、圆形按钮,兼容ie6
- 制作login.jsp页面,要求实现提供用户登陆的界面, 用户通过该界面输入用户名(控件名userName)和密码(控件名password), 然后点击“登录”按钮实现登陆操作.