vb.net中按钮控件制作不响应鼠标事件

代码如下,但是鼠标滑过的时候按钮的字体颜色不改变,请问这是为什么PublicClassRoundBtnDimtxtcAsColor=Color.WhiteProperty... 代码如下,但是鼠标滑过的时候按钮的字体颜色不改变,请问这是为什么

Public Class RoundBtn
Dim txtc As Color = Color.White
Property txtcolor() As Color
Get
Return txtc
End Get
Set(ByVal value As Color)
txtc = value
End Set
End Property
Private Sub RoundBtn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.Height = 25
.Width = 80
End With
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim bit As New Bitmap(Me.Width, Me.Height)
Dim pt As New Drawing2D.GraphicsPath
Dim g As Graphics = Me.CreateGraphics
Dim mp As New Pen(Color.LightGray, 3)
Dim w As Integer = Me.Width
Dim h As Integer = Me.Height
pt = GetRoundBtn()
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
Dim rect As New Rectangle(0, 0, w, h)
Dim mb As New Drawing2D.LinearGradientBrush(rect, Color.LightGray, Color.Black, 90)
Dim path4 As New Drawing2D.GraphicsPath
Dim path1bounds As RectangleF = pt.GetBounds
Dim rcText As New Rectangle(CInt(path1bounds.X), CInt(path1bounds.Y), CInt(path1bounds.Width), CInt(path1bounds.Height))
Dim strformat As New StringFormat
strformat.Alignment = StringAlignment.Center
strformat.LineAlignment = StringAlignment.Center
path4.AddString("Button1", Me.Font.FontFamily, CInt(Font.Style), 14, rcText, strformat)
Dim txtpen As New Pen(txtcolor, 1)
g.FillPath(mb, pt)
g.DrawPath(mp, pt)
g.DrawPath(txtpen, path4)
Me.Region = New Region(pt)
End Sub
Function GetRoundBtn()
Dim pt As New Drawing2D.GraphicsPath
Dim w As Integer = Me.Width
Dim h As Integer = Me.Height
Dim d As Integer = 3
With pt
.AddLine(d, 0, w - d, 0)
.AddLine(w - d, 0, w, d)
.AddLine(w, d, w, h - d)
.AddLine(w, h - d, w - d, h)
.AddLine(w - d, h, d, h)
.AddLine(d, h, 0, h - d)
.AddLine(0, h - d, 0, d)
.AddLine(0, d, d, 0)
End With
Return pt
End Function

Private Sub RoundBtn_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
txtcolor = Color.Red
Me.Cursor = Cursors.Hand
End Sub

Private Sub RoundBtn_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
txtcolor = Color.Red
Me.Cursor = Cursors.Default
End Sub
End Class
展开
 我来答
启岩
2010-06-03 · TA获得超过1851个赞
知道小有建树答主
回答量:809
采纳率:0%
帮助的人:644万
展开全部
Dim txtc As Color = Color.White
Property txtcolor() As Color
Get
Return txtc
End Get
Set(ByVal value As Color)
txtc = value
Me.invalidate()
End Set
End Property

Private Sub RoundBtn_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
txtc = Color.Red
Me.Cursor = Cursors.Hand
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式