You have made a widget so that you can say goodbye to the image button :)
Program source code:
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
{
/// <Summary>
/// Summary of UserControl1.
/// </Summary>
Public class UserControl1: Button
{
/// <Summary>
/// Required designer variables.
/// </Summary>
Private System. ComponentModel. Container components = null;
Private bool XiaCen = false;
Private bool mouseMove = false;
Private Color backColor;
Public UserControl1 ()
{
// This call is required by the Windows. Forms Form Designer.
InitializeComponent ();
// TODO: add any initialization after the InitComponent call
BackColor = this. backColor;
// This. Text = this. ShowFocusCues. ToString ();
}
/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void Dispose (bool disposing)
{
If (disposing)
{
If (components! = Null)
Components. Dispose ();
}
Base. Dispose (disposing );
}
# Code generated by the region component designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor
/// Modify the content of this method.
/// </Summary>
Private void InitializeComponent ()
{
//
// UserControl1
//
This. MouseUp + = new System. Windows. Forms. MouseEventHandler (this. usercontrol+mouseup );
This. Paint + = new System. Windows. Forms. PaintEventHandler (this. usercontrol+paint );
This. MouseEnter + = new System. EventHandler (this. usercontrol+mouseenter );
This. KeyUp + = new System. Windows. Forms. KeyEventHandler (this. usercontrolpolickeyup );
This. KeyDown + = new System. Windows. Forms. KeyEventHandler (this. usercontrolpolickeydown );
This. BackColorChanged + = new System. EventHandler (this. usercontrolpolicbackcolorchanged );
This. MouseLeave + = new System. EventHandler (this. usercontrol?mouseleave );
This. MouseDown + = new System. Windows. Forms. MouseEventHandler (this. usercontrol+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, limit F, 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 *;
Float bf4 = bf2 *;
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 *;
G = g + 3 *;
B = B + 3 *;
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 usercontrolinclumousedown (object sender, System. Windows. Forms. MouseEventArgs e)
{
If (XiaCen = false)
{
XiaCen = true;
This. Refresh ();
}
}
Private void usercontrolinclumouseup (object sender, System. Windows. Forms. MouseEventArgs e)
{
If (XiaCen = true)
{
XiaCen = false;
This. Refresh ();
}
}
Private void usercontrolpolicpaint (object sender, System. Windows. Forms. PaintEventArgs e)
{
}
Protected override void OnPaint (PaintEventArgs e)
{
Base. OnPaint (e );
E. Graphics. FillRectangle (new SolidBrush (backCol