Using system; using system.ComponentModel; use system.drawing; using system.drawing.drawing2d; using system.data; using system.windows.form;
Namespace LineargradientButtonLib {///
Private color frontcolor; // Button Gravity Prospects Private Color BackColor; // Button Gravity Background Color Private Bool IsUseangle; / / Whether to use angle private float angle; // Set angle private lineargradientMode mode; // Set linear gradient direction private StringAlignment textLineAlignment; // set the horizontal alignment of the button text private StringAlignment textVertAlignment; // set the vertical alignment of the button text private HatchStyle hatchStyle; private bool isUseHatchStyle // hatch pattern of the text; // settings are filled with a pattern
Public lineargradientButton () {// This call is required for the Windows.Forms Form Designer. InitializeComponent (); this.setStyle (ControlStyles.Userpaint | ControlStyles.allpaintinginwmpaint | ControlStyles.doublebuffer, true); // Todo: Add any initialization after INitComponent call
}
[Description ( "foreground gradient setting button"), Category ( "Appearance"), System.ComponentModel.RefreshProperties (RefreshProperties.Repaint)] public Color FrontColor {get {if (frontColor == Color.Empty) {frontColor = Color . Black;} Return FrontColor;} set {frontcolor = value;}}
[Description ( "background color gradation setting button"), Category ( "Appearance"), System.ComponentModel.RefreshProperties (RefreshProperties.Repaint)] public Color BackgroundColor {get {if (backColor == Color.Empty) {backColor = Color . White;} return backcolor;} set {backcolor = value;}} [defaultValue (false), Description ("Workero setting gravity angle")] public bool Usengle {get {return isuSeangle;} set {isusengle = value; }} [Description " WHILE (Angle> 360) {angle - = 360;} * / return = value;}} / * [defaultValue (stringAlignment.ceter), Description ("Setting the text level alignment") Category ("Appearance")] Public StringAlignment TextLineAlignment {Get {Return TextLineAlignment;} set {value = textLineAlignme Nt;}}
[DefaultValue (StringAlignment.Center), Description ( "vertical alignment of the text"), Category ( "Appearance")] public StringAlignment TextVertAlignment {get {return textVertAlignment;} set {value = textVertAlignment;}} * / [DefaultValue ( false), Description ( "whether the text pattern fill"), System.ComponentModel.RefreshProperties (RefreshProperties.All)] public bool UseHatchStyle {get {return isUseHatchStyle;} set {isUseHatchStyle = value;}}
[DefaultValue (0), Description ( "when UseAngle = false, the setting direction of the gradient"), Category ( "Appearance"), System.ComponentModel.RefreshProperties (RefreshProperties.Repaint)] public LinearGradientMode Mode {get {return mode;} set {mode = value;}} [DefaultValue (1), Description ( "set the text to be filled pattern"), Category ( "Appearance"), System.ComponentModel.RefreshProperties (RefreshProperties.Repaint)] public HatchStyle FillStyle {get {return HatchStyle;} set {hatchstyle = value;}}
///
#REGION component designer generated code ///
// Use the angle redraw button private void DrawButtonWithAngle (Graphics g) {LinearGradientBrush lgb = new LinearGradientBrush (new Rectangle (0,0, this.Width, this.Height), frontColor, backColor, angle); g.FillRectangle (lgb, 0, 0, this.width, this.height); lgb.dispose ();
// use a gradient fill mode button private void DrawButtonWithMode (Graphics g, LinearGradientMode mode) {LinearGradientBrush lgb = new LinearGradientBrush (new Rectangle (0,0, this.Width, this.Height), frontColor, backColor, mode); g.FillRectangle (LGB, 0, 0, THIS.WIDTH, THISHEIGHT); LGB.DISPOSE ();
Videos character pattern without // private void DrawButtonText (Graphics g) {StringFormat sf = new StringFormat (); //sf.LineAlignment = textLineAlignment; //sf.Alignment= textVertAlignment; sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.center; g.drawstring (this.text, this.font, new solidbrush (this.forecolor), New Rectangle (0,0, this.width, this.height), sf);} // Draw text private void DrawButtonText (Graphics g, HatchStyle hs) {StringFormat sf = new StringFormat (); //sf.LineAlignment = textLineAlignment; //sf.Alignment= textVertAlignment; sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center G.drawstring (THIS.TEXT, THIS.FONT, New Hatchbrush (HS, this.Forecolor, Color.aquamarine), New Rectangle (0, 0, THIS.WIDTH, THISHEIGHT), SF);
// override OnPaint event protected override void OnPaint (PaintEventArgs pea) {Graphics g = pea.Graphics; base.OnPaint (pea); if (UseAngle) DrawButtonWithAngle (g); else DrawButtonWithMode (g, Mode); if (UseHatchStyle) DrawButtonText (g, fillstyle); Else DrawButtonText (g);}}}