Today, I read "I have a C # write control", I wrote my own source code, but still attributes cannot be immediately iss

xiaoxiao2021-03-06  41

Using system; using system.ComponentModel; use system.drawing; using system.drawing.drawing2d; using system.data; using system.windows.form;

Namespace LineargradientButtonLib {///

/// UserControl1 Summary Description. /// public class lineargradientButton: system.windows.Forms.Button {/// // The required designer variable. /// private system.componentmodel.container components = null;

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

///

/// 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 vid initializecomponent () {components = new system.componentmodel.container ();} #ENDREGION

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

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

New Post(0)