发个自定义圆形Button(希望对新手有用)
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Data;
namespace IPlayControl
{
public class RoundButton:System.Windows.Forms.Button
{
public bool hasoutline = false;
protected bool down = false;
GraphicsPath path=new GraphicsPath();
private Image graphics;
private String text;
private Font Font = new Font("Arial", 16);
StringFormat format = StringFormat.GenericDefault;
FontFamily family = new FontFamily("Arial");
/* public Font Font
{
get { return font; }
set { font = value; Invalidate(); }
}*/
public override String Text
{
get { return text; }
set { text = value; Invalidate(); }
}
protected virtual Color GetColor()
{
Color[] colors ={ Color.Silver , Color.Gray };
return colors[Convert.ToInt32(down)];
}
protected virtual Brush GetBrush(bool buttonState)
{
return new LinearGradientBrush(new Point(2,2),new Point(Width -1,Height-1),Color.White,GetColor());
}
private int GetPenWidth()
{
return 1 + Convert.ToInt32(down);
}
private Pen GetPen()
{
return new Pen(Brushes.Black,GetPenWidth());
}
public void DrawButton(Graphics graphics)
{
graphics.FillEllipse(GetBrush(down),0,0,Width,Height);
//graphics.DrawEllipse(GetPen(),0,0,Width,Height);
}
public void DrawText(GraphicsPath path)
{
path.AddString(Text,family ,(int)FontStyle.Regular,Bounds.Height,new Point(0,0),format );
// graphics.DrawString(text,Font,Brushes.SpringGreen,new PointF(Width,Height));
}
public void DrawResize(GraphicsPath graphicspath)
{
graphicspath.AddEllipse(0,0,Width,Height);
}
public void DrawButtonImage(Graphics graphics)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
DrawButton(e.Graphics);
DrawGraphic(e.Graphics);
DrawText(path);
}
protected override void OnResize(EventArgs e)
{
path.AddEllipse(0,0,Bounds.Width,Bounds.Height);
Region = new Region(path);
Invalidate();
base.OnResize(e);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);
}
protected override void OnMouseUp(MouseEventArgs mevent)
{
base.OnMouseUp(mevent);
down = false;
Invalidate();
}
protected override void OnMouseDown(MouseEventArgs mevent)
{
base.OnMouseDown(mevent);
down = true;
Invalidate();
}
protected virtual void DrawDownGraphic(Graphics graphics)
{
Matrix m = new Matrix();
m.Scale(1.03f,1.03f);
graphics.Transform = m;
}
protected virtual void DrawGraphic(Graphics graphics)
{
if (down)
DrawDownGraphic(graphics);
}
protected virtual Brush GraphicBrush()
{
return Enabled ? Brushes.Black : Brushes.Silver;
}
}
}
...全文
相关推荐
圆形Button(源码+Demo)
圆形Button(源码+Demo)。。。。。
C#自定义控件:一个简单的圆形按钮源码
VS2010下,C#自定义控件源代码示例,为一个圆形的Button控件,包括dll和源文件项目
android相机圆形框拍照,自定义拍照界面
android相机自定义圆形框拍照,保留圆形照片。
Android自定义圆形SeekBar
自定义的圆弧行SeekBar。(PS:不支持0%-100%跳转)
Android布局自定义Shap圆形ImageView可以单独设置背景与图片
主要介绍了Android布局自定义Shap圆形ImageView可以单独设置背景与图片 的相关资料,需要的朋友可以参考下



