Solved

Disable a textbox (winforms) but without changing colors?

Posted on 2006-06-19
4
2,145 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 70

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 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