Основываясь на this project (как писал выше) Я переписан пользовательский класс Datepicker (в VB.NET), которая позволяет настраивать цвет фона, TextColor и маленькое изображение появляются рядом с кнопкой выпадающего меню.
Eg.1:
Eg.2:
Чтобы заставить его работать просто создать новый класс в проект со следующим кодом и Перестроить решение , Новый элемент управления под названием MyDateTimePicker должен появиться в списке панели инструментов:
Public Class MyDateTimePicker
Inherits System.Windows.Forms.DateTimePicker
Private _disabled_back_color As Color
Private _image As Image
Private _text_color As Color = Color.Black
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
_disabled_back_color = Color.FromKnownColor(KnownColor.Control)
End Sub
''' <summary>
''' Gets or sets the background color of the control
''' </summary>
<Browsable(True)>
Public Overrides Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set
MyBase.BackColor = Value
End Set
End Property
''' <summary>
''' Gets or sets the background color of the control when disabled
''' </summary>
<Category("Appearance"), Description("The background color of the component when disabled")>
<Browsable(True)>
Public Property BackDisabledColor() As Color
Get
Return _disabled_back_color
End Get
Set
_disabled_back_color = Value
End Set
End Property
''' <summary>
''' Gets or sets the Image next to the dropdownbutton
''' </summary>
<Category("Appearance"),
Description("Get or Set the small Image next to the dropdownbutton")>
Public Property Image() As Image
Get
Return _image
End Get
Set(ByVal Value As Image)
_image = Value
Invalidate()
End Set
End Property
''' <summary>
''' Gets or sets the text color when calendar is not visible
''' </summary>
<Category("Appearance")>
Public Property TextColor As Color
Get
Return _text_color
End Get
Set(value As Color)
_text_color = value
End Set
End Property
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = Me.CreateGraphics()
g.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
'Dropdownbutton rectangle
Dim ddb_rect As New Rectangle(ClientRectangle.Width - 17, 0, 17, ClientRectangle.Height)
'Background brush
Dim bb As Brush
Dim visual_state As ComboBoxState
'When enabled the brush is set to Backcolor,
'otherwise to color stored in _disabled_back_Color
If Me.Enabled Then
bb = New SolidBrush(Me.BackColor)
visual_state = ComboBoxState.Normal
Else
bb = New SolidBrush(Me._disabled_back_color)
visual_state = ComboBoxState.Disabled
End If
'Filling the background
g.FillRectangle(bb, 0, 0, ClientRectangle.Width, ClientRectangle.Height)
'Drawing the datetime text
g.DrawString(Me.Text, Me.Font, New SolidBrush(TextColor), 5, 2)
'Drawing icon
If Not _image Is Nothing Then
Dim im_rect As New Rectangle(ClientRectangle.Width - 40, 4, ClientRectangle.Height - 8, ClientRectangle.Height - 8)
g.DrawImage(_image, im_rect)
End If
'Drawing the dropdownbutton using ComboBoxRenderer
ComboBoxRenderer.DrawDropDownButton(g, ddb_rect, visual_state)
g.Dispose()
bb.Dispose()
End Sub
End Class
* Обратите внимание, что этот класс упрощен, поэтому имеет ограниченную функциональность,
Жаль, что так долго не принималось. Я надеялся, что есть другие решения, которые не предполагали знание шестнадцатеричных значений, а затем я забыл об этом. – 2009-01-05 18:47:11
Спасибо за сообщение. Я настраиваю элемент управления DateTimePicker, и это ставит меня в правильном направлении. – 2009-02-13 22:33:37
Я пробовал это изменение под Vista (с визуальными стилями и без них), и он не работает. – 2009-02-16 05:53:12