我正在尝试为自定义按钮控件创建一个类,该类的顶部和底部颜色将带有2个渐变的圆角。以下是在顶部和底部为我提供两个渐变颜色的代码。但是,我遇到了一些问题,其中鼠标悬停属性不起作用并且图像也未显示(因为新成分的颜色与按钮文本和隐藏在渐变颜色后面的图像重叠)
除了渐变色和圆角之外,有人可以帮助我使用该控件的所有控件都应该像在Windows按钮控件上一样工作吗?
[如果您需要任何其他信息,请告诉我们。
谢谢。
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Class MyButton
Inherits Button
Private m_TopColor As Color = Color.LightGreen
Private m_BottomColor As Color = Color.Orange
Public Property TopColor As Color
Get
Return m_TopColor
End Get
Set(ByVal value As Color)
m_TopColor = value
Me.Invalidate()
End Set
End Property
Public Property BottomColor As Color
Get
Return m_BottomColor
End Get
Set(ByVal value As Color)
m_BottomColor = value
Me.Invalidate()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Using lgb As LinearGradientBrush = New LinearGradientBrush(Me.ClientRectangle, m_TopColor, m_BottomColor, 90.0F)
Using textBrush As SolidBrush = New SolidBrush(Me.ForeColor)
Using format As StringFormat = New StringFormat()
format.Alignment = GetHorizontalAlignment()
format.LineAlignment = GetVerticalAlignment()
e.Graphics.FillRectangle(lgb, Me.ClientRectangle)
e.Graphics.DrawString(Me.Text, Me.Font, textBrush, Me.ClientRectangle, format)
End Using
End Using
End Using
End Sub
Private Function GetVerticalAlignment() As StringAlignment
Return CType(Math.Log(Me.TextAlign, 2D) / 4, StringAlignment)
End Function
Private Function GetHorizontalAlignment() As StringAlignment
Return CType(Math.Log(Me.TextAlign, 2D) Mod 4, StringAlignment)
End Function
End Class
我正在尝试为自定义按钮控件创建一个类,该类的顶部和底部颜色将带有2个渐变的圆角。以下是在顶部和底部为我提供两个渐变颜色的代码。 ...
自定义圆形按钮,代码: