Figurer
Figurer
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace CustomControls.RJControls
{
public class RJButton : Button
{
//Fields
private int borderSize = 0;
private int borderRadius = 0;
private Color borderColor = Color.PaleVioletRed;
//Properties
[Category("RJ Code Advance")]
public int BorderSize
{
get { return borderSize; }
set
{
borderSize = value;
this.Invalidate();
}
}
//Constructor
public RJButton()
{
this.FlatStyle = FlatStyle.Flat;
this.FlatAppearance.BorderSize = 0;
this.Size = new Size(150, 40);
this.BackColor = Color.MediumSlateBlue;
this.ForeColor = Color.White;
this.Resize += new EventHandler(Button_Resize);
}
//Methods
private GraphicsPath GetFigurePath(Rectangle rect, int radius)
{
GraphicsPath path = new GraphicsPath();
float curveSize = radius * 2F;
path.StartFigure();
path.AddArc(rect.X, rect.Y, curveSize, curveSize, 180, 90);
path.AddArc(rect.Right - curveSize, rect.Y, curveSize, curveSize, 270,
90);
path.AddArc(rect.Right - curveSize, rect.Bottom - curveSize, curveSize,
curveSize, 0, 90);
path.AddArc(rect.X, rect.Bottom - curveSize, curveSize, curveSize, 90,
90);
path.CloseFigure();
return path;
}
//Button border
if (borderSize >= 1)
//Draw control border
pevent.Graphics.DrawPath(penBorder, pathBorder);
}
}
else //Normal button
{
pevent.Graphics.SmoothingMode = SmoothingMode.None;
//Button surface
this.Region = new Region(rectSurface);
//Button border
if (borderSize >= 1)
{
using (Pen penBorder = new Pen(borderColor, borderSize))
{
penBorder.Alignment = PenAlignment.Inset;
pevent.Graphics.DrawRectangle(penBorder, 0, 0, this.Width -
1, this.Height - 1);
}
}
}
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
this.Parent.BackColorChanged += new
EventHandler(Container_BackColorChanged);
}