Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disable a textbox (winforms) but without changing colors?

Posted on 2006-06-19
4
Medium Priority
?
2,205 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 2000 total points
ID: 16938534
see an article I wrote in July 2005 from http://emoreau.s2i.com/
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

879 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