I have this code for making a custom disabled control that allows you to change the background and foreground colors on a TextBox...Problem is that when it is fired the properties I've set in the regular textbox properties are ignored, specifically the textalign property. Why is this happening and how can I fix it?Code:Option Strict On Imports System.Drawing Imports System.Windows.Forms Imports System.ComponentModel Public Class TextboxExtended Inherits System.Windows.Forms.TextBox ' Color used for background and foreground when ' control is diabled Private _BackColorDisabled As Color = Color.LightYellow Private _ForeColorDisabled As Color = Color.Black <Category("Appearance"), _ Description("Sets the BackColor to Non-Standard when Disabled"), _ DefaultValue(GetType(Color), "Light Yellow")> _ Public Property BackColorDisabled() As Color Get Return _BackColorDisabled End Get Set(ByVal Value As Color) _BackColorDisabled = Value End Set End Property <Category("Appearance"), _ Description("Sets the BackColor to Non-Standard when Disabled"), _ DefaultValue(GetType(Color), "Black")> _ Public Property ForeColorDisabled() As Color Get Return _ForeColorDisabled End Get Set(ByVal Value As Color) _ForeColorDisabled = Value End Set End Property Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) ' Set the TextBrush with the color to paint disabled control text Dim TextBrush As SolidBrush = New SolidBrush(Me._ForeColorDisabled) ' Is the Control Disabled If Not Me.Enabled Then ' The control is diabled use BackColorDisabled porperty for background Dim BackBrush As New SolidBrush(_BackColorDisabled) e.Graphics.FillRectangle(BackBrush, 0.0F, 0.0F, Me.Width, Me.Height) End If ' Panint the text with the ForeColorDisabled color e.Graphics.DrawString(Me.Text, Me.Font, TextBrush, 0.0F, 0.0F) End Sub Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs) MyBase.OnEnabledChanged(e) If Not Me.Enabled Then Me.SetStyle(ControlStyles.UserPaint, True) Else Me.SetStyle(ControlStyles.UserPaint, False) End If End Sub End Class




Reply With Quote