[ASP.NET] Written Crystal Button

xiaoxiao2021-03-06  106

effect:

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 {///

/// userControl1 summary description. /// public class userControl1: button {/// // The required designer variable. /// private System.ComponentModel.Container components = null; private bool XiaCen = false; private bool mouseMove = false; private Color backColor; public UserControl1 () {// This call is Windows.Forms Form Designer It is necessary. InitializationComponent ();

// Todo: Add any initialization backcolor = this.backcolor; //this.text =tis.showfocuscues.toString ();

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) Components.dispose ();} Base.Dispose (Disposing);

#REGION component designer generated code ///

/// designer supports the required method - Do not use the code editor // to modify the contents of this method. /// private void InitializeComponent () {// // UserControl1 // this.MouseUp = new System.Windows.Forms.MouseEventHandler (this.UserControl1_MouseUp); this.Paint = new System.Windows.Forms .PaintEventHandler (this.UserControl1_Paint); this.MouseEnter = new System.EventHandler (this.UserControl1_MouseEnter); this.KeyUp = new System.Windows.Forms.KeyEventHandler (this.UserControl1_KeyUp); this.KeyDown = new System. Windows.Forms.KeyEventHandler (this.UserControl1_KeyDown); this.BackColorChanged = new System.EventHandler (this.UserControl1_BackColorChanged); this.MouseLeave = new System.EventHandler (this.UserControl1_MouseLeave); this.MouseDown = new System.Windows .Forms.mouseeventhandler (this.userControl1_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 . HeightPath.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, 190F, 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; rest.y = rest.y this.clientRectangle. Height / 4; if (xiacen) {RECT.Y = Rect.y 4;} graphicspath path; for (int A = 1; a <33; A ) {float bf3 = bf1 * a; float bf4 = bf2 * a Recting 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 * a; g = g 3 * a; b = b 3 * a; 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.draw String (THIS.TEXT, FONT, New Solidbrush (Color.Fromargb (0x66, BackColor)), Rect, StringFormat; g.drawstring (this.text, font, new solidbrush (this.forecolor), Rect1, stringFormat;} private void UserControl1_MouseDown (object sender, System.Windows.Forms.MouseEventArgs e) {if (XiaCen == false) {XiaCen = true; this.Refresh ();}} private void UserControl1_MouseUp (object sender, System.Windows.Forms. MouseEventArgs E) {ix == True) {xiacen = false; this.refresh ();}}

private void UserControl1_Paint (object sender, System.Windows.Forms.PaintEventArgs e) {} protected override void OnPaint (PaintEventArgs e) {base.OnPaint (e); e.Graphics.FillRectangle (new SolidBrush (backColor), 0,0, this.Width, this.Height); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; Rectangle rect = new Rectangle (0,0, this.Width, this.Height); GraphicsPath ClientPath = GetGraphicsPath (rect); e.Graphics.FillPath (new SolidBrush (backColor), ClientPath); this.Region = new System.Drawing.Region (ClientPath); DrawYinYing (e.Graphics, XiaCen); DrawGaoLiang (e.Graphics, Xiacen; DrawText (E.Graphics, Xiacen; if (this.focused) {E.Graphics.drawpath (New Pen (Color.Fromargb (0x22, 0xFF, 0xFF, 0xFF), 3), ClientPath;}} private Void UserControl1_backcolorchanged (Object sender, system.eventargs e) {int R = backcolor.r; int g = backcolor.g; int b = backcolor.b; r = r 0x22; g = g 0x22; b = b 0x2 2; if (r> 255) r = 255; if (g> 255) g = 255; if (b> 255) b = 255; backcolor = color.fromargb (r, g, b);}

Private void UserControl1_keydown (ibject sender, system.windows.forms.keyeventargs e) {iCen == false && e.Keycode == Keys.Space) {xiacen = true; this.refresh ();}}

Private void UserControl1_keyup (object sender, system.windows.forms.keyeventargs e) {iCen == true && e.Keycode == keys.Space) {xiacen = false; this.refresh ();}}

private void UserControl1_MouseEnter (object sender, System.EventArgs e) {if (mouseMove == false) {mouseMove = true; this.Refresh ();}} private void UserControl1_MouseLeave (object sender, System.EventArgs e) {if (mouseMove = = True) {mousemove = false; this.refresh ();}}}}

转载请注明原文地址:https://www.9cbs.com/read-101329.html

New Post(0)