Bei diesem Code funktioniert zwar die Eigenschaft BackColor, jedoch kann der Benutzer nicht mehr manuell reinschreiben und ich kann nicht mit der TAB - Taste zum Control springen. :S
Edit: Aufs Control springen kann man, allerdings sieht man nicht, wann das Control den Fokus hat.
' *****************************************
' ** Author: Vincenzo Rossi **
' ** Year : 2008 **
' ** Mail : redmaster@tiscali.it **
' ** **
' ** Released under **
' ** The Code Project Open License **
' *****************************************
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms.VisualStyles
''' <summary>
''' A derivation of DateTimePicker allowing to change background color
''' </summary>
Class BCDateTimePicker
Inherits System.Windows.Forms.DateTimePicker
Private _backDisabledColor As Color
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
_backDisabledColor = 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(ByVal value As Color)
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 _backDisabledColor
End Get
Set(ByVal value As Color)
_backDisabledColor = value
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As _
System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = Me.CreateGraphics
'Graphics g = e.Graphics;
'The dropDownRectangle defines position and size of dropdownbutton
' block,
'the width is fixed to 17 and height to 16. The dropdownbutton is
' aligned to right
Dim dropDownRectangle As Rectangle = New Rectangle(( _
ClientRectangle.Width - 17), 0, 17, 16)
Dim bkgBrush As Brush
Dim visualState As ComboBoxState
'When the control is enabled the brush is set to Backcolor,
'otherwise to color stored in _backDisabledColor
If Me.Enabled Then
bkgBrush = New SolidBrush(Me.BackColor)
visualState = ComboBoxState.Normal
Else
bkgBrush = New SolidBrush(Me._backDisabledColor)
visualState = ComboBoxState.Disabled
End If
' Painting...in action
'Filling the background
g.FillRectangle(bkgBrush, 0, 0, ClientRectangle.Width, _
ClientRectangle.Height)
'Drawing the datetime text
g.DrawString(Me.Text, Me.Font, Brushes.Black, 0, 2)
'Drawing the dropdownbutton using ComboBoxRenderer
ComboBoxRenderer.DrawDropDownButton(g, dropDownRectangle, visualState)
g.Dispose()
bkgBrush.Dispose()
End Sub
End Class
Beitrag wurde zuletzt am 06.10.11 um 17:03:40 editiert. |