The effect is as follows:
It is relatively simple, the following is the source code, create a new type of library project, copy the following source code override Class1, can use the DLL file can be used
Public class xpstylebutton inherits system.windows.Forms.userControl
#Region "Windows Form Designer Generated Code"
Public Sub new () mybase.new ()
'This call is required for the Windows Form Designer. InitializeComponent ()
'Add any initialization setStyle (ControlStyles.allpaintinginwmpaint or controlstyles.doublebuffer or controlstyles.Userpaint, true) End Sub
'UserControl1 Rewinds Dispose to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End Sub
'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer
'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.
End Sub
#End Region Private IsMouseDown As Boolean = False Private xMagin As Integer = 2 Private yMagin As Integer = 2 Private m_BackColor As Color = Color.BurlyWood Private m_ForeColor As Color = Color.White Private m_Style As Style = Style.RectStyle 'button's Styles Public Enum Style RectStyle = 0 EllipseStionyl = 1 CircleStyle = 2 End Enum
'-------------------- Above the external properties --------------' Bright PUBLIC Property LightColor () As Color Get Return M_ForeColor End Get Set (ByVal Value As Color) m_ForeColor = Value End Set End Property 'dark Public Property GrayColor () As Color Get Return Me.m_BackColor End Get Set (ByVal Value As Color) Me.m_BackColor = Value End Set End Property Public Property ButtonStyle () AS Style Get Return Me.m_Style End Get Set (Byval Value As Style) IF Value = Style.Circlelection = style = me.width end if me.m_style = value End set end 在 p 双 双 重 重 双 双Button Private Sub XpStyleButton_Paint (ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Me.BackColor = Me.Parent.BackColor Dim brush As Drawing.Drawing2D.LinearGradientBrush Dim brush1 A s Drawing.Drawing2D.LinearGradientBrush brush = New Drawing.Drawing2D.LinearGradientBrush (New PointF (0, 0), New PointF (0, Me.Height), Me.m_ForeColor, Me.m_BackColor) 'in response to mouse clicks If Me. isMouseDown Then brush1 = New Drawing.Drawing2D.LinearGradientBrush (New PointF (xMagin, yMagin), New PointF (xMagin, Me.Height), Color.FromArgb (0, 255, 255, 255), Color.FromArgb (150, 255, 255, 255) Else brush1 = new drawing.drawing2d.Lineargradientbrush (New Pointf (Xmagin, Ymagin), New Pointf (Xmagin, Me.Height / 2), Color.Fromargb (150, 255, 255, 255), Color. FromARGB (0, 255, 255, 255)) end if brush.wrapmode =
Drawing.Drawing2D.WrapMode.TileFlipX brush1.WrapMode = Drawing.Drawing2D.WrapMode.TileFlipXDim rect As Rectangle = New Rectangle (0, 0, Me.Width - xMagin, Me.Height - yMagin) Dim rect1 As Rectangle = New Rectangle (xMagin , yMagin, Me.Width - 2 * xMagin, Me.Height / 2) Select Case Me.m_Style Case Style.RectStyle Me.DrawRectStyle (e.Graphics, rect, rect1, brush, brush1) Case Style.EllipseStyle Me.DrawEllipseStyle ( e.Graphics, rect, rect1, brush, brush1) Case Style.CircleStyle Me.DrawEllipseStyle (e.Graphics, rect, rect1, brush, brush1) Case Else Me.DrawRectStyle (e.Graphics, rect, rect1, brush, brush1) End SELECT
End Sub 'Videos oval button (the button is round by the re-drawing) Private Sub DrawEllipseStyle (ByRef g As Graphics, ByVal rect As Rectangle, ByVal rect1 As Rectangle, ByVal bbrush As Brush, ByVal fbrush As Brush) g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias g.FillEllipse (bbrush, rect) g.FillEllipse (fbrush, rect) g.DrawEllipse (New Pen (m_BackColor), rect) End Sub 'Videos rectangular button Private Sub DrawRectStyle (ByRef g As Graphics, ByVal rect As Rectangle, ByVal rect1 As Rectangle, ByVal bbrush As Brush, ByVal fbrush As Brush) g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias g.FillRectangle (bbrush, rect) g.FillRectangle (fbrush, rect) g.DrawRectangle (New Pen (m_BackColor), rect) End Sub Private Sub XpStyleButton_MouseDown (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown isMouseDown = True Me.Refresh () End Sub
Private Sub XpStyleButton_MouseUp (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp IsMouseDown = False Me.Refresh () End SubEnd Class following are the test source code needs to be added to generate the above-referenced Dll :
Public class form1 inherits system.windows.Forms.form
#Region "Windows Form Designer Generated Code"
Public Sub new () mybase.new ()
'This call is required for the Windows Form Designer. InitializeComponent ()
'Add any initialization after INITIALIZECOMPONENT ()
End Sub
'Form rewriting disposal to clean the component list. Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose () End If End If MyBase.Dispose (disposing) End Sub Private button1 As XPStyleButton.XpStyleButton 'Windows Forms Designer Private components as system.com required by the instrument
'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.
Friend WithEvents XpStyleButton1 As XPStyleButton.XpStyleButton Friend WithEvents XpStyleButton4 As XPStyleButton.XpStyleButton
Me.XpStyleButton4.BackColor = System.Drawing.SystemColors.Control Me.XpStyleButton4.ButtonStyle = XPStyleButton.XpStyleButton.Style.CircleStyle Me.XpStyleButton4.GrayColor = System.Drawing.Color.BurlyWood Me.XpStyleButton4.LightColor = System.Drawing.Color .White Me.XpStyleButton4.Location = New System.Drawing.Point (168, 16) Me.XpStyleButton4.Name = "XpStyleButton4" Me.XpStyleButton4.Size = New System.Drawing.Size (96, 96) Me.XpStyleButton4.TabIndex = 2 '' Form1 'me.autoscalebasesize = new system.drawing.size (6, 14) me.clientsize = new system.drawing.size (520, 273) me.controls.addrange (new system.windows.Forms.Control () {Me.button1, me.xpstylebutton4, me.xpStyleButton1} me.name = "form1" me.text = "form1" me.resumeLayout (false) end sub
#End region
Thank you for reading, I hope there is any opinion to contact me, ganelenping @ mainone.com.cn QQ: 44460100