Solved

Disable a textbox (winforms) but without changing colors?

Posted on 2006-06-19
4
2,126 Views
Last Modified: 2008-02-07
Hi there,

Can anyone suggest a way to disable textboxes and stop them getting focus without changing the colours..

I have tried putting the textboxes in panels and groupboxes ... and then disabling the group/panel.. and it does work but the textboxes automatically change colors to look like they are dimmed... and i want to stop this...

Can anyone help?

Thanks in advance

Ian
0
Comment
Question by:ianinspain
4 Comments
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 16935070
make it readOnly
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16935359
From http://www.windowsforms.net/FAQs/default.aspx?PageID=3&CategoryID=3&SubcategoryID=78:


How do I specify the text color of a read-only or disabled TextBox?  
 
When I set a TextBox to Readonly or set Enabled to false, the text color is gray. How can I force it to be the color specified in the ForeColor property of the TextBox?

You can download a VB.NET sample.

Override the OnPaint event of the TextBox. For example:

protected override void OnPaint(PaintEventArgs e)
{
  SolidBrush drawBrush = new SolidBrush( ForeColor ); //Use the ForeColor property
  // Draw string to screen.
  e.Graphics.DrawString( Text, Font, drawBrush, 0f, 0f ); //Use the Font property
}


Note: You need to set the ControlStyles to "UserPaint" in the constructor.

public MyTextBox()
{
  // This call is required by the Windows.Forms Form Designer.
  SetStyle( ControlStyles.UserPaint, true );
  InitializeComponent();
}


0
 
LVL 5

Expert Comment

by:pgloor
ID: 16935452
Make the TextBox'es ReadOnly AND set the BackColor to the color you want to see
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 16938534
see an article I wrote in July 2005 from http://emoreau.s2i.com/
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query datatable in LINQ 6 39
Async and await with MVC and Web Api 3 29
Linq help 1 16
Check my code out(2) 1 29
Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now