C # under the rewrite button control

xiaoxiao2021-03-06  66

XpButton.cs code using system;

Using system.windows;

Using system.drawing;

Using system.drawing.drawing2d;

Using system.windows .forms;

Namespace Xpctrl

{

///

/// XpButton's summary description.

///

Public class xpbutton: System.windows.Forms.Button

{

Private bool mouseover = false;

Public xpbutton ()

{

//

// TODO: Add constructor logic here

//

this.cursor = system.windows.forms.cursors.hand;

}

Protected Override Void Onpaint (System.Windows.Forms.Painteventargs E)

{

// Base.onpaint (e);

// system.drawing.graphics pp = this.creategraphics ();

// E.Graphics.clear (color.Transparent);

// E.Graphics.drawellipse (new system.drawing.pen (system.drawing.color.whitesmoke, 5), 0, 0, this.width, this.height);

// system.drawing.solidbrush dd = new solidbrush (system.drawing.color.whitesmoke);

// E.Graphics.Fillellipse (DD, 0, 0, this.width, this.Height);

// (this.backcolor.tostring ())

Color C5 = color.fromargb

(255, 255, 255);

Color C2 = color.fromargb

(192, 192, 192);

IF (Mouseover)

{

C5 = color.fromargb (245, 245, 245);

//c2=color.fromargb (192, 192, 192);

C2 = color.fromargb (180, 175, 190);

}

Brush b = new system.drawing.drawing2d.Lineargradientbrush

ClientRectangle, C5, C2, LineargradientMode.Vertical;

//System.drawing.region=new region

INT offsetwidth = this.width / 50;

Point [] Points = New Point [8];

Points [0] .x = offsetwidth;

Points [0] .y = 0;

Points [1] .x = this.width-offsetwidth;

Points [1] .y = 0;

Points [2] .x = this.width;

Points [2] .y = offsetwidth;

Points [3] .x = this.width;

Points [3] .y = this.height-offsetwidth;

Points [4] .x = this.width-offetwidth;

Points [4] .y = this.height;

Points [5] .x = offsetwidth; points [5] .y = this.height;

Points [6] .x = 0;

Points [6] .y = this.height-offsetwidth;

Points [7] .x = 0;

Points [7] .y = offsetwidth;

// E.Graphics.FillRectangle (B, ClientRectangle);

E.Graphics.FillPolygon (B, Points, FillMode.Winding);

IF (this.focused)

{

INT offsetWidth1 = (this.width-5) / 50 2;

Point [] Points1 = New Point [8];

Points1 [0] .x = offsetwidth1;

Points1 [0] .y = 2;

Points1 [1] .x = this.width-offsetwidth1;

Points1 [1] .y = 2;

Points1 [2] .x = this.width-1;

Points1 [2] .y = offsetwidth1;

Points1 [3] .x = this.width-1;

Points1 [3] .y = this.height-offsetwidth1;

Points1 [4] .x = this.width-offsetwidth1;

Points1 [4] .y = this.Height-1;

Points1 [5] .x = 1;

Points1 [5] .y = this.Height-1;

Points1 [6] .x = 2;

Points1 [6] .y = this.height-offsetwidth1;

Points1 [7] .x = 2;

Points1 [7] .y = OFFSETWIDTH1;

// E.Graphics.drawPolygon (New Pen (Color.Yellow, 2), Points1);

Pen P = New Pen (Color.range, 2);

Pen P1 = New Pen (Color.wheat, 2);

//p.dashstyle=dashstyle.dashdot;

E.Graphics.drawline (P1, Points1 [0], Points1 [1]);

E.Graphics.drawline (p, points1 [1], points1 [2]);

E.Graphics.drawline (p, points1 [2], points1 [3]);

E.Graphics.drawline (p, points1 [3], points1 [4]);

E.Graphics.drawline (P, Points1 [4], Points1 [5]);

E.Graphics.drawline (P, Points1 [5], Points1 [6]);

E.Graphics.drawline (P1, Points1 [6], Points1 [7]);

E.Graphics.drawline (P1, Points1 [7], Points1 [0]);

}

E.Graphics.drawPolygon (New Pen (Color.darkBlue, 2), Points;

// E.Graphics.drawline (New Pen (Color.darkBlue, 2), New Point (0, 0), New Point (this.width, 0);

// E.Graphics.drawline (New Pen (Color.darkBlue, 2), New Point (0, 0), New Point (0, this.Height);

// E.Graphics.drawline (New Pen (THIS.WIDTH, THIS.HEIGHT), New Point (this.width, 0)); // E.Graphics.Drawline (New Pen (COLOR.DARKBLUE, 2), New Point (this.width, this.height), New Point (0, this.Height));

StringFormat DrawFormat = new stringFormat ();

DrawFormat.formatflags = stringFormatFlags.displayFormatControl;

DrawFormat.LineAlignment = stringalignment.center;

DrawFormat.Alignment = system.drawing.stringAlignment.Center;

E.Graphics.drawstring (this.text, this.font, new lineargradientbrush (this.clientRectangle, color.black, color.ble, lineargradientmode.vertage), this.clientRectangle, DrawFormat;

b.dispose ();

}

Protected Override Void Onleave (Eventargs E)

{

Base.onleave (e);

}

// Protected Override Void OnMousehover (Eventargs E)

// {

//

// mouseover = TRUE;

// this.invalidate (false);

// Base.onMousehover (e);

//}

Protected Override Void OnmouseEnter (Eventargs E)

{

mouseover = true;

This.INValidate (false);

Base.onmouseEnter (e);

}

Protected Override Void OnnotifyMessage (System.Windows.Forms.Message M)

{

Base.onnotifyMessage (M);

}

Protected Override Void OnMouseLeave (Eventargs E)

{

MouseOver = false;

This.INValidate (false);

Base.onmouseLeave (e);

}

Private void DrawButton (System.drawing.graphics G)

{

}

Protected Override Void onPaintBackground (System.Windows.Forms.PainteventArgs PEVENT)

{

// color c5 = color.fromargb

// (255, 255, 255);

// color C2 = color.fromargb

// (192, 192, 192);

// if (mouseover)

// {

// c5 = color.fromargb (245, 245, 245);

////C2=color.fromargb (192,192,192) ;// c2 = color.fromargb (180, 175, 190);

//}

// brush b = new system.drawing.drawing2d.LineargradientBrush

// (ClientRectangle, C5, C2, lineargradientmode.vertage);

//pevent.graphics .drawRectangle (New Pen (Color.Transparent, 2), this.clientRectangle;

PEVENT.GRAPHICS .CLAR (color.wheat);

//base.onpaintbackground (pevent);

}

}

}

Call in Form1.cs

My method is to drag a Windows's Button to come over, change two places.

One is a variable definition:

Private xpctrl.xpbutton button1;

The other is the code generated by the Windows Form Designer:

THIS.BUTTON1 = New XpCtrl.xpbutton ();

effect:

This color I use is gray, and if you change to color, you can be very beautiful.

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

New Post(0)