关于XP样式按钮的问题
小弟,最近优化软件,找到一个可以优化按钮为xp效果的代码,可是不知道为什么其中有一个变量总是没有声明。很是郁闷,请高手告诉我怎么样才能声明么?谢了
InitializeComponent()就是这个变量没有声明
找了别的窗口代码,找了一句声明这个函数的语句 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
可是也插不进去,什么地方都不让放,请问这是为什么啊~谢谢大虾了,小弟不才。。
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("Red")> 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)
Else '一般情况下
DrawNormalButton(pevent.Graphics)
End If
'写文本
WriteText(pevent.Graphics)
End Sub
'鼠标按下的状态处理
Private Sub my_OnMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
my_mouseDown = True '鼠标按下
End Sub
'鼠标松开状态的处理
Private Sub my_OnMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
my_mouseDown = False '鼠标松开
'重新绘制控件时发生 Paint 事件。PaintEventArgs 指定绘制控件所用的 Graphics
'以及绘制控件所在的 ClipRectangle。
Dim pe As PaintEventArgs = New PaintEventArgs(CreateGraphics(), ClientRectangle)
OnPaint(pe)
End Sub
'鼠标进入
Private Sub my_OnMouseEnter(ByVal sender As Object, ByVal e As EventArgs)
my_mouseHover = True '鼠标移动到其上
Dim pe As PaintEventArgs = New PaintEventArgs(CreateGraphics(), ClientRectangle)
OnPaint(pe)
End Sub
'鼠标移动开
Private Sub my_OnMouseLeave(ByVal sender As Object, ByVal e As EventArgs)
my_mouseHover = False '鼠标移动开
Dim pe As PaintEventArgs = New PaintEventArgs(CreateGraphics(), ClientRectangle)
OnPaint(pe)
End Sub