C # Program Generation of the crystal button

Source: Internet
Author: User
Tags drawtext bf4

C # in the crystal buttonProgramGenerate
Copyright codesky.net 2003-2005
Posting time: keywords: Unknown

You have made a widget so that you can say goodbye to the image button :)

ProgramSource 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 );
}

# Generated by the region component designer Code
/// <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 = 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 (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 usercontrolpolicbackcolorchanged (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 + 0x22;
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 (Object sender, system. Windows. Forms. keyeventargs E)
{
If (xiacen = false & E. keycode = keys. Space)
{
Xiacen = true;
This. Refresh ();
}
}

Private void usercontrolpolickeyup (Object sender, system. Windows. Forms. keyeventargs E)
{
If (xiacen = true & E. keycode = keys. Space)
{
Xiacen = false;
This. Refresh ();
}
}

Private void usercontrol+mouseenter (Object sender, system. eventargs E)
{
If (mousemove = false)
{
Mousemove = true;
This. Refresh ();
}
}

Private void usercontrolpolicmouseleave (Object sender, system. eventargs E)
{
If (mousemove = true)
{
Mousemove = false;
This. Refresh ();
}
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.