Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing forecolor of disabled controls
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01345277
Message ID:
01345811
Views:
36
Thanks, Farhad. This will be helpful when I get ready to build my own set of controls. I like Eric's solution for my current situation because I can just extend the existing controls without having to replace all my existing controls.

>> Is there any way to change the forecolor on a disabled control, such as a text box? The contrast is so low as to be nearly unreadable and my user really wants to have controls disabled unless the user selects the edit or new button. Thanks.
>
>----
>
>It's possible to generate a new class based on your control, customize and define an override OnPaint for it..
>
>For example for a TextBox control:
>- Add a new class to your solution
>- Define your new class based on TextBox
>
>    public class MyTextBox : TextBox
>    {
>        public MyTextBox()
>        {
>            this.SetStyle(ControlStyles.UserPaint, true);
>        }
>
>        protected override void OnPaint(PaintEventArgs e)
>        {
>            SolidBrush myDrwBrush = new SolidBrush(Color.Black);
>            e.Graphics.DrawString(this.Text, this.Font, myDrwBrush, 0F, 0F);
>        }
>    }
>
>- Instantiate an object from the new class on your form
>- Customize its properties
>- Add it to your form controls like this:
>
>            MyTextBox myTxtBox = new MyTextBox();
>            
>            myTxtBox.Location = new System.Drawing.Point(12, 36);
>            myTxtBox.Name = "myTxtBox";
>            myTxtBox.Size = new System.Drawing.Size(260, 20);
>            myTxtBox.Text = "This is a test text box";
>
>            this.Controls.Add(myTxtBox);
>
>
>- Disable it in your code to see the effect:
>
>this.Controls["myTxtBox"].Enabled = false
>
>
>I found the following URL useful:
>http://www.syncfusion.com/faq/windowsforms/faq_c94c.aspx#q866q
>
>Hope it helps
Linda Harmes
HiBit Technologies, Inc.
Previous
Reply
Map
View

Click here to load this message in the networking platform