' Custom control that draws the caption for each pane. Contains an active ' state and draws the caption different for each state. Caption is drawn ' with a gradient fill and antialias font. Imports System.Drawing.Drawing2D '使用GDI+绘制渐变背景和表面文字需要引用的类 Imports System.ComponentModel
PublicClass PaneCaptionClass PaneCaption
Inherits System.Windows.Forms.UserControl
' const values '用来控制控件表面文字绘制的属性和控件默认的缺省属性 PrivateClass ConstsClass Consts
PublicConst DefaultHeight AsInteger=26 PublicConst DefaultFontName AsString="Tahoma" PublicConst DefaultFontSize AsInteger=12 PublicConstPosOffset AsInteger=4'文字相对于容器的绘制坐标位移 End Class ' internal members Private m_active AsBoolean=False'控件激活和无效两种状态控制 Private m_antiAlias AsBoolean=True'用来控制控件表面文字的显示质量 Private m_allowActive AsBoolean=True Private m_text AsString=""
'两种状态默认文字、背景渐变颜色 Private m_colorActiveText As Color = Color.Black
Private m_colorInactiveText As Color = Color.White
Private m_colorActiveLow As Color = Color.FromArgb(255, 165, 78)
Private m_colorActiveHigh As Color = Color.FromArgb(255, 225, 155)
Private m_colorInactiveLow As Color = Color.FromArgb(3, 55, 145)
Private m_colorInactiveHigh As Color = Color.FromArgb(90, 135, 215)
' gdi objects '绘制显示效果的笔刷 Private m_brushActiveText As SolidBrush
Private m_brushInactiveText As SolidBrush
Private m_brushActive As LinearGradientBrush
Private m_brushInactive AsLinearGradientBrush Private m_format As StringFormat
' public properties ' the caption of the control '设置控件中的文本,并且在属性面板中可以选择 <Description("Text displayed in the caption."), _
Category("Appearance"), DefaultValue("")> _
PublicProperty Caption()Property Caption() AsString Get Return m_text
EndGet Set(ByVal value AsString)
m_text = value
Invalidate()'重会控件的显示 EndSet End Property '两个同样的属性,但是在即使按照上边控制Caption属性的方式来控制Text属性,属性面板中也不显示Text属性,不知动为什么? PublicOverridesProperty Text()Property Text() AsString Get Return Me.Caption
EndGet Set(ByVal Value AsString)
Me.Caption = Value
EndSet End Property ' if the caption is active or not <Description("The active state of the caption, draws the caption with different gradient colors."), _
Category("Appearance"), DefaultValue(False)> _
PublicProperty Active()Property Active() AsBoolean Get Return m_active
EndGet Set(ByVal value AsBoolean)
m_active = value
Invalidate()
EndSet End Property ' if should maintain an active and inactive state <Description("True always uses the inactive state colors, false maintains an active and inactive state."), _
Category("Appearance"), DefaultValue(True)> _
PublicProperty AllowActive()Property AllowActive() AsBoolean Get Return m_allowActive
EndGet Set(ByVal value AsBoolean)
m_allowActive = value
Invalidate()
EndSet End Property ' if the caption is active or not <Description("If should draw the text as antialiased."), _
Category("Appearance"), DefaultValue(True)> _
PublicProperty AntiAlias()Property AntiAlias() AsBoolean Get Return m_antiAlias
EndGet Set(ByVal value AsBoolean)
m_antiAlias = value
Invalidate()
EndSet End Property #Region " color properties "
<Description("Color of the text when active."), _
Category("Appearance"), DefaultValue(GetType(Color), "Black")>_
PublicProperty ActiveTextColor()Property ActiveTextColor() As Color
Get Return m_colorActiveText
EndGet Set(ByVal Value As Color)
IfValue.Equals(Color.Empty)Then Value = Color.Black
m_colorActiveText = Value
m_brushActiveText =New SolidBrush(m_colorActiveText)
Invalidate()
EndSet End Property <Description("Color of the text when inactive."), _
Category("Appearance"), DefaultValue(GetType(Color), "White")> _
PublicProperty InactiveTextColor()Property InactiveTextColor() As Color
Get Return m_colorInactiveText
EndGet Set(ByVal Value As Color)
If Value.Equals(Color.Empty) Then Value = Color.White
m_colorInactiveText = Value
m_brushInactiveText =New SolidBrush(m_colorInactiveText)
Invalidate()
EndSet End Property <Description("Low color of the active gradient."), _
Category("Appearance"), DefaultValue(GetType(Color), "255, 165, 78")> _
PublicProperty ActiveGradientLowColor()Property ActiveGradientLowColor() As Color
Get Return m_colorActiveLow
EndGet Set(ByVal Value As Color)
If Value.Equals(Color.Empty) Then Value = Color.FromArgb(255, 165, 78)
m_colorActiveLow = Value
CreateGradientBrushes()
Invalidate()
EndSet End Property <Description("High color of the active gradient."), _
Category("Appearance"), DefaultValue(GetType(Color), "255, 225, 155")> _
PublicProperty ActiveGradientHighColor()Property ActiveGradientHighColor() As Color
Get Return m_colorActiveHigh
EndGet &#