日期:2012-02-08 浏览次数:20401 次
Imports System.Drawing
Imports System.ComponentModel
Public Class winxpbutton
Inherits System.Windows.Forms.Button
Private my_mouseDown As Boolean = False '鼠标按下
Private my_mouseHover As Boolean = False '鼠标移到上面
Private m_textcolor As Color = System.Drawing.Color.Black '字体颜色
<Description("字体颜色。")> _
Public Property textcolor() As Color
Get
Return m_textcolor
End Get
Set(ByVal Value As Color)
m_textcolor = Value
Me.Invalidate()
End Set
End Property
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化,true表示将指定的样式应用到控件
'设置控件样式位能够充分地更改控件行为
Me.SetStyle(ControlStyles.UserPaint, True)
'关联事件委托
AddHandler Me.MouseDown, AddressOf my_OnMouseDown
AddHandler Me.MouseUp, AddressOf my_OnMouseUp
AddHandler Me.MouseEnter, AddressOf my_OnMouseEnter
AddHandler Me.MouseLeave, AddressOf my_OnMouseLeave
Height = 23
Width = 75
End Sub
Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
'pevent.ClipRectangle指在其中绘制的矩形,即使用父控件的背景色来画这个矩形按钮
pevent.Graphics.FillRectangle(New SolidBrush(Me.Parent.BackColor), pevent.ClipRectangle)
If (Enabled = False) Then
'画不可用状态
DrawDisableButton(pevent.Graphics)
ElseIf (my_mouseDown) Then '画鼠标按下状态
DrawMouseDownButton(pevent.Graphics)
ElseIf (my_mouseHover) Then '画鼠标移动到其上状态
DrawMouseHoverButton(pevent.Graphics)
ElseIf (Focused) Then '有焦点,但鼠标未移动到其上
DrawContainFocusButton(pevent.Graphics)