110,534
社区成员
发帖
与我相关
我的任务
分享
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;
}
}
}