类QQ的XP BUTTON控件

Imports System
Imports System.Enum
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System.Drawing.Design

Namespace LandlordAspx_xpctrl

Public Class emunType

Public Enum XPStyle
Default1
Blue
OliveGreen
Silver
End Enum

Public Enum BtnShape
Rectangle
Ellipse
End Enum
End Class

Friend NotInheritable Class ControlPaint

Private Sub New()
End Sub

Public Shared ReadOnly Property BorderColor() As Color
Get
Return Color.FromArgb(127, 157, 185)
End Get
End Property

Public Shared ReadOnly Property DisabledBorderColor() As Color
Get
Return Color.FromArgb(201, 199, 186)
End Get
End Property

Public Shared ReadOnly Property ButtonBorderColor() As Color
Get
Return Color.FromArgb(28, 81, 128)
End Get
End Property

Public Shared ReadOnly Property DisabledButtonBorderColor() As Color
Get
Return Color.FromArgb(202, 200, 187)
End Get
End Property

Public Shared ReadOnly Property DisabledBackColor() As Color
Get
Return Color.FromArgb(236, 233, 216)
End Get
End Property

Public Shared ReadOnly Property DisabledForeColor() As Color
Get
Return Color.FromArgb(161, 161, 146)
End Get
End Property

Public Shared Function GetStringFormat(ByVal contentAlignment As ContentAlignment) As StringFormat
If Not System.Enum.IsDefined(GetType(ContentAlignment), CType(contentAlignment, Integer)) Then
Throw New System.ComponentModel.InvalidEnumArgumentException("contentAlignment", CType(contentAlignment, Integer), GetType(ContentAlignment))
End If
Dim stringFormat As StringFormat = New StringFormat
Select Case contentAlignment
Case contentAlignment.MiddleCenter
stringFormat.LineAlignment = StringAlignment.Center
stringFormat.Alignment = StringAlignment.Center
' break
Case contentAlignment.MiddleLeft
stringFormat.LineAlignment = StringAlignment.Center
stringFormat.Alignment = StringAlignment.Near
' break
Case contentAlignment.MiddleRight
stringFormat.LineAlignment = StringAlignment.Center
stringFormat.Alignment = StringAlignment.Far
' break
Case contentAlignment.TopCenter
stringFormat.LineAlignment = StringAlignment.Near
stringFormat.Alignment = StringAlignment.Center
' break
Case contentAlignment.TopLeft
stringFormat.LineAlignment = StringAlignment.Near
stringFormat.Alignment = StringAlignment.Near
' break
Case contentAlignment.TopRight
stringFormat.LineAlignment = StringAlignment.Near
stringFormat.Alignment = StringAlignment.Far
' break
Case contentAlignment.BottomCenter
stringFormat.LineAlignment = StringAlignment.Far
stringFormat.Alignment = StringAlignment.Center
' break
Case contentAlignment.BottomLeft
stringFormat.LineAlignment = StringAlignment.Far
stringFormat.Alignment = StringAlignment.Near
' break
Case contentAlignment.BottomRight
stringFormat.LineAlignment = StringAlignment.Far
stringFormat.Alignment = StringAlignment.Far
' break
End Select
Return stringFormat
End Function

Public Shared Sub DrawRoundedRectangle(ByVal g As Graphics, ByVal p As Pen, ByVal rc As Rectangle, ByVal size As Size)
Dim oldSmoothingMode As SmoothingMode = g.SmoothingMode
g.SmoothingMode = SmoothingMode.AntiAlias
g.DrawLine(p, CType(rc.Left + size.Width / 2, Single), rc.Top, CType(rc.Right - size.Width / 2, Single), rc.Top)
g.DrawArc(p, rc.Right - size.Width, rc.Top, size.Width, size.Height, 270, 90)
g.DrawLine(p, rc.Right, CType(rc.Top + size.Height / 2, Single), rc.Right, CType(rc.Bottom - size.Height / 2, Single))
g.DrawArc(p, rc.Right - size.Width, rc.Bottom - size.Height, size.Width, size.Height, 0, 90)
g.DrawLine(p, CType(rc.Right - size.Width / 2, Single), rc.Bottom, CType(rc.Left + size.Width / 2, Single), rc.Bottom)
g.DrawArc(p, rc.Left, rc.Bottom - size.Height, size.Width, size.Height, 90, 90)
g.DrawLine(p, rc.Left, CType(rc.Bottom - size.Height / 2, Single), rc.Left, CType(rc.Top + size.Height / 2, Single))
g.DrawArc(p, rc.Left, rc.Top, size.Width, size.Height, 180, 90)
g.SmoothingMode = oldSmoothingMode
End Sub

Public Shared Sub DrawBorder(ByVal g As Graphics, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
g.DrawRectangle(New Pen(ControlPaint.BorderColor, 0), x, y, width, height)
End Sub

Public Shared Sub EraseExcessOldDropDown(ByVal g As Graphics, ByVal newButton As Rectangle)
g.FillRectangle(New SolidBrush(SystemColors.Window), newButton.X - 2, newButton.Y, 2, newButton.Height + 1)
End Sub
End Class

Public Class XP_Button
Inherits System.Windows.Forms.Button

Public Enum ControlState
Normal
Hover
Pressed
Default1
Disabled
End Enum

Private components As System.ComponentModel.Container

Public Sub New()
MyBase.New()

InitializeComponent()

Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer, True)

End Sub

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

  1<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()   
  2'   
  3'XPButton   
  4'   
  5Me.Name = "XPButton" 
  6
  7End Sub 
  8
  9  
 10#Region "Static members" 
 11
 12Private Shared ReadOnly sizeBorderPixelIndent As Size = New Size(4, 4)   
 13Dim clrOuterShadow1 As Color = Color.FromArgb(64, 164, 164, 164)   
 14Dim clrOuterShadow2 As Color = Color.FromArgb(64, Color.White)   
 15Dim clrBackground1 As Color = Color.FromArgb(250, 250, 248)   
 16Dim clrBackground2 As Color = Color.FromArgb(240, 240, 234)   
 17Dim clrBorder As Color = Color.FromArgb(0, 60, 116)   
 18Dim clrInnerShadowBottom1 As Color = Color.FromArgb(236, 235, 230)   
 19Dim clrInnerShadowBottom2 As Color = Color.FromArgb(226, 223, 214)   
 20Dim clrInnerShadowBottom3 As Color = Color.FromArgb(214, 208, 197)   
 21Dim clrInnerShadowRight1a As Color = Color.FromArgb(128, 236, 234, 230)   
 22Dim clrInnerShadowRight1b As Color = Color.FromArgb(128, 224, 220, 212)   
 23Dim clrInnerShadowRight2a As Color = Color.FromArgb(128, 234, 228, 218)   
 24Dim clrInnerShadowRight2b As Color = Color.FromArgb(128, 212, 208, 196)   
 25Dim clrInnerShadowBottomPressed1 As Color = Color.FromArgb(234, 233, 227)   
 26Dim clrInnerShadowBottomPressed2 As Color = Color.FromArgb(242, 241, 238)   
 27Dim clrInnerShadowTopPressed1 As Color = Color.FromArgb(209, 204, 193)   
 28Dim clrInnerShadowTopPressed2 As Color = Color.FromArgb(220, 216, 207)   
 29Dim clrInnerShadowLeftPressed1 As Color = Color.FromArgb(216, 213, 203)   
 30Dim clrInnerShadowLeftPressed2 As Color = Color.FromArgb(222, 220, 211) 
 31
 32#End Region 
 33
 34#Region "Constructors"   
 35'Shared EDButton()   
 36'sizeBorderPixelIndent = New Size(4, 4)   
 37'clrOuterShadow1 = Color.FromArgb(64, 164, 164, 164)   
 38'clrOuterShadow2 = Color.FromArgb(64, Color.White)   
 39'clrBackground1 = Color.FromArgb(250, 250, 248)   
 40'clrBackground2 = Color.FromArgb(240, 240, 234)   
 41'clrBorder = Color.FromArgb(0, 60, 116)   
 42' clrInnerShadowBottom1 = Color.FromArgb(236, 235, 230)   
 43'clrInnerShadowBottom2 = Color.FromArgb(226, 223, 214)   
 44'clrInnerShadowBottom3 = Color.FromArgb(214, 208, 197)   
 45'clrInnerShadowRight1a = Color.FromArgb(128, 236, 234, 230)   
 46'clrInnerShadowRight1b = Color.FromArgb(128, 224, 220, 212)   
 47'clrInnerShadowRight2a = Color.FromArgb(128, 234, 228, 218)   
 48' clrInnerShadowRight2b = Color.FromArgb(128, 212, 208, 196)   
 49' clrInnerShadowBottomPressed1 = Color.FromArgb(234, 233, 227)   
 50'clrInnerShadowBottomPressed2 = Color.FromArgb(242, 241, 238)   
 51'clrInnerShadowTopPressed1 = Color.FromArgb(209, 204, 193)   
 52'clrInnerShadowTopPressed2 = Color.FromArgb(220, 216, 207)   
 53' clrInnerShadowLeftPressed1 = Color.FromArgb(216, 213, 203)   
 54'clrInnerShadowLeftPressed2 = Color.FromArgb(222, 220, 211)   
 55'End Sub   
 56#End Region 
 57
 58#Region "Properties"   
 59Dim enmState As ControlState = ControlState.Normal   
 60Dim bCanClick As Boolean = False   
 61Dim m_btnStyle As emunType.XPStyle = emunType.XPStyle.Default1   
 62Dim m_btnShape As emunType.BtnShape = emunType.BtnShape.Rectangle   
 63Dim locPoint As Point 
 64
 65Public Shadows Property FlatStyle() As FlatStyle   
 66Get   
 67Return MyBase.FlatStyle   
 68End Get   
 69Set(ByVal Value As FlatStyle)   
 70MyBase.FlatStyle = FlatStyle.Standard   
 71End Set   
 72End Property 
 73
 74Public Property BtnShape() As emunType.BtnShape   
 75Get   
 76Return m_btnShape   
 77End Get   
 78Set(ByVal Value As emunType.BtnShape)   
 79m_btnShape = Value   
 80MyBase.Invalidate()   
 81End Set   
 82End Property 
 83
 84<defaultvalue("blue"), system.componentmodel.refreshproperties(refreshproperties.repaint)=""> _   
 85Public Property BtnStyle() As emunType.XPStyle   
 86Get   
 87Return m_btnStyle   
 88End Get   
 89Set(ByVal Value As emunType.XPStyle)   
 90m_btnStyle = Value   
 91Me.Invalidate()   
 92End Set   
 93End Property 
 94
 95Public Property AdjustImageLocation() As Point   
 96Get   
 97Return locPoint   
 98End Get   
 99Set(ByVal Value As Point)   
100locPoint = Value   
101Me.Invalidate()   
102End Set   
103End Property 
104
105Private ReadOnly Property BorderRectangle() As Rectangle   
106Get   
107Dim rc As Rectangle = Me.ClientRectangle   
108Return New Rectangle(1, 1, rc.Width - 3, rc.Height - 3)   
109End Get   
110End Property 
111
112#End Region 
113
114#Region "Methods" 
115
116Protected Overloads Overrides Sub OnClick(ByVal ea As EventArgs)   
117Me.Capture = False   
118bCanClick = False   
119If Me.ClientRectangle.Contains(Me.PointToClient(Control.MousePosition)) Then   
120enmState = ControlState.Hover   
121Else   
122enmState = ControlState.Normal   
123End If   
124Me.Invalidate()   
125MyBase.OnClick(ea)   
126End Sub 
127
128Protected Overloads Overrides Sub OnMouseEnter(ByVal ea As EventArgs)   
129MyBase.OnMouseEnter(ea)   
130enmState = ControlState.Hover   
131Me.Invalidate()   
132End Sub 
133
134Protected Overloads Overrides Sub OnMouseDown(ByVal mea As MouseEventArgs)   
135MyBase.OnMouseDown(mea)   
136If mea.Button = MouseButtons.Left Then   
137bCanClick = True   
138enmState = ControlState.Pressed   
139Me.Invalidate()   
140End If   
141End Sub 
142
143Protected Overloads Overrides Sub OnMouseMove(ByVal mea As MouseEventArgs)   
144MyBase.OnMouseMove(mea)   
145If ClientRectangle.Contains(mea.X, mea.Y) Then   
146If enmState = ControlState.Hover AndAlso Me.Capture AndAlso Not bCanClick Then   
147bCanClick = True   
148enmState = ControlState.Pressed   
149Me.Invalidate()   
150End If   
151Else   
152If enmState = ControlState.Pressed Then   
153bCanClick = False   
154enmState = ControlState.Hover   
155Me.Invalidate()   
156End If   
157End If   
158End Sub 
159
160Protected Overloads Overrides Sub OnMouseLeave(ByVal ea As EventArgs)   
161MyBase.OnMouseLeave(ea)   
162enmState = ControlState.Normal   
163Me.Invalidate()   
164End Sub 
165
166Protected Overloads Overrides Sub OnPaint(ByVal pea As PaintEventArgs)   
167Me.OnPaintBackground(pea)   
168Select Case enmState   
169Case ControlState.Normal   
170If Me.Enabled Then   
171If Me.Focused OrElse Me.IsDefault Then   
172Select Case m_btnShape   
173Case emunType.BtnShape.Rectangle   
174OnDrawDefault(pea.Graphics)   
175' break   
176Case emunType.BtnShape.Ellipse   
177OnDrawDefaultEllipse(pea.Graphics)   
178' break   
179End Select   
180Else   
181Select Case m_btnShape   
182Case emunType.BtnShape.Rectangle   
183OnDrawNormal(pea.Graphics)   
184' break   
185Case emunType.BtnShape.Ellipse   
186OnDrawNormalEllipse(pea.Graphics)   
187' break   
188End Select   
189End If   
190Else   
191OnDrawDisabled(pea.Graphics)   
192End If   
193' break   
194Case ControlState.Hover   
195Select Case m_btnShape   
196Case emunType.BtnShape.Rectangle   
197OnDrawHover(pea.Graphics)   
198' break   
199Case emunType.BtnShape.Ellipse   
200OnDrawHoverEllipse(pea.Graphics)   
201' break   
202End Select   
203' break   
204Case ControlState.Pressed   
205Select Case m_btnShape   
206Case emunType.BtnShape.Rectangle   
207OnDrawPressed(pea.Graphics)   
208' break   
209Case emunType.BtnShape.Ellipse   
210OnDrawPressedEllipse(pea.Graphics)   
211' break   
212End Select   
213' break   
214End Select   
215OnDrawTextAndImage(pea.Graphics)   
216End Sub 
217
218Protected Overloads Overrides Sub OnEnabledChanged(ByVal ea As EventArgs)   
219MyBase.OnEnabledChanged(ea)   
220enmState = ControlState.Normal   
221Me.Invalidate()   
222End Sub 
223
224Private Sub OnDrawNormal(ByVal g As Graphics)   
225DrawNormalButton(g)   
226End Sub 
227
228Private Sub OnDrawHoverEllipse(ByVal g As Graphics)   
229DrawNormalEllipse(g)   
230DrawEllipseHoverBorder(g)   
231DrawEllipseBorder(g)   
232End Sub 
233
234Private Sub OnDrawHover(ByVal g As Graphics)   
235DrawNormalButton(g)   
236Dim rcBorder As Rectangle = Me.BorderRectangle   
237Dim penTop1 As Pen = New Pen(Color.FromArgb(255, 240, 207))   
238Dim penTop2 As Pen = New Pen(Color.FromArgb(253, 216, 137))   
239g.DrawLine(penTop1, rcBorder.Left + 2, rcBorder.Top + 1, rcBorder.Right - 2, rcBorder.Top + 1)   
240g.DrawLine(penTop2, rcBorder.Left + 1, rcBorder.Top + 2, rcBorder.Right - 1, rcBorder.Top + 2)   
241penTop1.Dispose()   
242penTop2.Dispose()   
243Dim penBottom1 As Pen = New Pen(Color.FromArgb(248, 178, 48))   
244Dim penBottom2 As Pen = New Pen(Color.FromArgb(229, 151, 0))   
245g.DrawLine(penBottom1, rcBorder.Left + 1, rcBorder.Bottom - 2, rcBorder.Right - 1, rcBorder.Bottom - 2)   
246g.DrawLine(penBottom2, rcBorder.Left + 2, rcBorder.Bottom - 1, rcBorder.Right - 2, rcBorder.Bottom - 1)   
247penBottom1.Dispose()   
248penBottom2.Dispose()   
249Dim rcLeft As Rectangle = New Rectangle(rcBorder.Left + 1, rcBorder.Top + 3, 2, rcBorder.Height - 5)   
250Dim rcRight As Rectangle = New Rectangle(rcBorder.Right - 2, rcBorder.Top + 3, 2, rcBorder.Height - 5)   
251Dim brushSide As LinearGradientBrush = New LinearGradientBrush(rcLeft, Color.FromArgb(254, 221, 149), Color.FromArgb(249, 180, 53), LinearGradientMode.Vertical)   
252g.FillRectangle(brushSide, rcLeft)   
253g.FillRectangle(brushSide, rcRight)   
254brushSide.Dispose()   
255End Sub 
256
257Private Sub OnDrawPressedEllipse(ByVal g As Graphics)   
258DrawPressedEllipse(g)   
259DrawEllipseBorder(g)   
260End Sub 
261
262Private Sub DrawPressedEllipse(ByVal g As Graphics)   
263Dim rcBorder As Rectangle = Me.BorderRectangle   
264Dim rcBackground As Rectangle = New Rectangle(rcBorder.X + 1, rcBorder.Y + 1, rcBorder.Width - 1, rcBorder.Height - 1)   
265Dim brushBackground As SolidBrush = New SolidBrush(Color.FromArgb(226, 225, 218))   
266g.FillEllipse(brushBackground, rcBackground)   
267End Sub 
268
269Private Sub OnDrawPressed(ByVal g As Graphics)   
270Dim rcBorder As Rectangle = Me.BorderRectangle   
271DrawOuterShadow(g)   
272Dim rcBackground As Rectangle = New Rectangle(rcBorder.X + 1, rcBorder.Y + 1, rcBorder.Width - 1, rcBorder.Height - 1)   
273Dim brushBackground As SolidBrush = New SolidBrush(Color.FromArgb(226, 225, 218))   
274g.FillRectangle(brushBackground, rcBackground)   
275brushBackground.Dispose()   
276DrawBorder(g)   
277Dim penInnerShadowBottomPressed1 As Pen = New Pen(clrInnerShadowBottomPressed1)   
278Dim penInnerShadowBottomPressed2 As Pen = New Pen(clrInnerShadowBottomPressed2)   
279g.DrawLine(penInnerShadowBottomPressed1, rcBorder.Left + 1, rcBorder.Bottom - 2, rcBorder.Right - 1, rcBorder.Bottom - 2)   
280g.DrawLine(penInnerShadowBottomPressed2, rcBorder.Left + 2, rcBorder.Bottom - 1, rcBorder.Right - 2, rcBorder.Bottom - 1)   
281penInnerShadowBottomPressed1.Dispose()   
282penInnerShadowBottomPressed2.Dispose()   
283Dim penInnerShadowTopPressed1 As Pen = New Pen(clrInnerShadowTopPressed1)   
284Dim penInnerShadowTopPressed2 As Pen = New Pen(clrInnerShadowTopPressed2)   
285g.DrawLine(penInnerShadowTopPressed1, rcBorder.Left + 2, rcBorder.Top + 1, rcBorder.Right - 2, rcBorder.Top + 1)   
286g.DrawLine(penInnerShadowTopPressed2, rcBorder.Left + 1, rcBorder.Top + 2, rcBorder.Right - 1, rcBorder.Top + 2)   
287penInnerShadowTopPressed1.Dispose()   
288penInnerShadowTopPressed2.Dispose()   
289Dim penInnerShadowLeftPressed1 As Pen = New Pen(clrInnerShadowLeftPressed1)   
290Dim penInnerShadowLeftPressed2 As Pen = New Pen(clrInnerShadowLeftPressed2)   
291g.DrawLine(penInnerShadowLeftPressed1, rcBorder.Left + 1, rcBorder.Top + 3, rcBorder.Left + 1, rcBorder.Bottom - 3)   
292g.DrawLine(penInnerShadowLeftPressed2, rcBorder.Left + 2, rcBorder.Top + 3, rcBorder.Left + 2, rcBorder.Bottom - 3)   
293penInnerShadowLeftPressed1.Dispose()   
294penInnerShadowLeftPressed2.Dispose()   
295End Sub 
296
297Private Sub OnDrawNormalEllipse(ByVal g As Graphics)   
298DrawNormalEllipse(g)   
299DrawEllipseBorder(g)   
300End Sub 
301
302Private Sub OnDrawDefaultEllipse(ByVal g As Graphics)   
303DrawNormalEllipse(g)   
304DrawEllipseDefaultBorder(g)   
305DrawEllipseBorder(g)   
306End Sub 
307
308Private Sub OnDrawDefault(ByVal g As Graphics)   
309DrawNormalButton(g)   
310Dim rcBorder As Rectangle = Me.BorderRectangle   
311Dim penTop1 As Pen = New Pen(Color.FromArgb(206, 231, 255))   
312Dim penTop2 As Pen = New Pen(Color.FromArgb(188, 212, 246))   
313g.DrawLine(penTop1, rcBorder.Left + 2, rcBorder.Top + 1, rcBorder.Right - 2, rcBorder.Top + 1)   
314g.DrawLine(penTop2, rcBorder.Left + 1, rcBorder.Top + 2, rcBorder.Right - 1, rcBorder.Top + 2)   
315penTop1.Dispose()   
316penTop2.Dispose()   
317Dim penBottom1 As Pen = New Pen(Color.FromArgb(137, 173, 228))   
318Dim penBottom2 As Pen = New Pen(Color.FromArgb(105, 130, 238))   
319g.DrawLine(penBottom1, rcBorder.Left + 1, rcBorder.Bottom - 2, rcBorder.Right - 1, rcBorder.Bottom - 2)   
320g.DrawLine(penBottom2, rcBorder.Left + 2, rcBorder.Bottom - 1, rcBorder.Right - 2, rcBorder.Bottom - 1)   
321penBottom1.Dispose()   
322penBottom2.Dispose()   
323Dim rcLeft As Rectangle = New Rectangle(rcBorder.Left + 1, rcBorder.Top + 3, 2, rcBorder.Height - 5)   
324Dim rcRight As Rectangle = New Rectangle(rcBorder.Right - 2, rcBorder.Top + 3, 2, rcBorder.Height - 5)   
325Dim brushSide As LinearGradientBrush = New LinearGradientBrush(rcLeft, Color.FromArgb(186, 211, 245), Color.FromArgb(137, 173, 228), LinearGradientMode.Vertical)   
326g.FillRectangle(brushSide, rcLeft)   
327g.FillRectangle(brushSide, rcRight)   
328brushSide.Dispose()   
329End Sub 
330
331Private Sub OnDrawDisabled(ByVal g As Graphics)   
332Dim rcBorder As Rectangle = Me.BorderRectangle   
333Dim rcBackground As Rectangle = New Rectangle(rcBorder.X + 1, rcBorder.Y + 1, rcBorder.Width - 1, rcBorder.Height - 1)   
334Dim brushBackground As SolidBrush = New SolidBrush(Color.FromArgb(245, 244, 234))   
335g.FillRectangle(brushBackground, rcBackground)   
336brushBackground.Dispose()   
337Dim penBorder As Pen = New Pen(Color.FromArgb(201, 199, 186))   
338ControlPaint.DrawRoundedRectangle(g, penBorder, rcBorder, sizeBorderPixelIndent)   
339penBorder.Dispose()   
340End Sub 
341
342Private Sub OnDrawTextAndImage(ByVal g As Graphics)   
343Dim brushText As SolidBrush   
344If Enabled Then   
345brushText = New SolidBrush(ForeColor)   
346Else   
347brushText = New SolidBrush(ControlPaint.DisabledForeColor)   
348End If   
349Dim sf As StringFormat = ControlPaint.GetStringFormat(Me.TextAlign)   
350sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show   
351If Not (Me.Image Is Nothing) Then   
352Dim rc As Rectangle = New Rectangle   
353Dim ImagePoint As Point = New Point(6, 4)   
354Select Case Me.ImageAlign   
355Case ContentAlignment.MiddleRight   
356rc.Width = Me.ClientRectangle.Width - Me.Image.Width - 8   
357rc.Height = Me.ClientRectangle.Height   
358rc.X = 0   
359rc.Y = 0   
360ImagePoint.X = rc.Width   
361ImagePoint.Y = Me.ClientRectangle.Height / 2 - Image.Height / 2   
362' break   
363Case ContentAlignment.TopCenter   
364ImagePoint.Y = 2   
365ImagePoint.X = (Me.ClientRectangle.Width - Me.Image.Width) / 2   
366rc.Width = Me.ClientRectangle.Width   
367rc.Height = Me.ClientRectangle.Height - Me.Image.Height - 4   
368rc.X = Me.ClientRectangle.X   
369rc.Y = Me.Image.Height   
370' break   
371Case ContentAlignment.MiddleCenter   
372ImagePoint.X = (Me.ClientRectangle.Width - Me.Image.Width) / 2   
373ImagePoint.Y = (Me.ClientRectangle.Height - Me.Image.Height) / 2   
374rc.Width = 0   
375rc.Height = 0   
376rc.X = Me.ClientRectangle.Width   
377rc.Y = Me.ClientRectangle.Height   
378' break   
379Case Else   
380ImagePoint.X = 6   
381ImagePoint.Y = Me.ClientRectangle.Height / 2 - Image.Height / 2   
382rc.Width = Me.ClientRectangle.Width - Me.Image.Width   
383rc.Height = Me.ClientRectangle.Height   
384rc.X = Me.Image.Width   
385rc.Y = 0   
386' break   
387End Select   
388ImagePoint.X += locPoint.X   
389ImagePoint.Y += locPoint.Y   
390If Me.Enabled Then   
391g.DrawImage(Me.Image, ImagePoint)   
392Else   
393System.Windows.Forms.ControlPaint.DrawImageDisabled(g, Me.Image, locPoint.X, locPoint.Y, Me.BackColor)   
394End If   
395If Not (ContentAlignment.MiddleCenter = Me.ImageAlign) Then   
396Dim rs As RectangleF   
397rs.X = rc.X   
398rs.Y = rc.Y   
399rs.Width = rc.Width   
400rs.Height = rc.Height   
401g.DrawString(Me.Text, Me.Font, brushText, rs, sf)   
402End If   
403Else   
404Dim rs As RectangleF   
405rs.X = Me.ClientRectangle.X   
406rs.Y = Me.ClientRectangle.Y   
407rs.Width = Me.ClientRectangle.Width   
408rs.Height = Me.ClientRectangle.Height   
409g.DrawString(Me.Text, Me.Font, brushText, rs, sf)   
410End If   
411brushText.Dispose()   
412sf.Dispose()   
413End Sub 
414
415Private Sub DrawNormalEllipse(ByVal g As Graphics)   
416Dim rcBackground As Rectangle = Me.BorderRectangle   
417Dim brushBackground As LinearGradientBrush = Nothing   
418Select Case m_btnStyle   
419Case emunType.XPStyle.Default1   
420brushBackground = New LinearGradientBrush(rcBackground, clrBackground1, clrBackground2, LinearGradientMode.Vertical)   
421' break   
422Case emunType.XPStyle.Blue   
423brushBackground = New LinearGradientBrush(rcBackground, Color.FromArgb(248, 252, 253), Color.FromArgb(172, 171, 201), LinearGradientMode.Vertical)   
424' break   
425Case emunType.XPStyle.OliveGreen   
426brushBackground = New LinearGradientBrush(rcBackground, Color.FromArgb(250, 250, 240), Color.FromArgb(235, 220, 190), LinearGradientMode.Vertical)   
427' break   
428Case emunType.XPStyle.Silver   
429brushBackground = New LinearGradientBrush(rcBackground, Color.FromArgb(253, 253, 253), Color.FromArgb(205, 205, 205), LinearGradientMode.Vertical)   
430' break   
431End Select   
432Dim relativeIntensities() As Single = {0, 0.008, 1}   
433Dim relativePositions() As Single = {0, 0.22, 1}   
434Dim blend As Blend = New Blend   
435blend.Factors = relativeIntensities   
436blend.Positions = relativePositions   
437brushBackground.Blend = blend   
438g.FillEllipse(brushBackground, rcBackground)   
439End Sub 
440
441Private Sub DrawNormalButton(ByVal g As Graphics)   
442Dim rcBorder As Rectangle = Me.BorderRectangle   
443DrawOuterShadow(g)   
444Dim rcBackground As R</defaultvalue("blue"),></system.diagnostics.debuggerstepthrough()>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus