Solved

Disable a textbox (winforms) but without changing colors?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 65
Create XML 5 46
Calling stored proc in EDMX 11 23
how to read json value 2 29
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 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

22 Experts available now in Live!

Get 1:1 Help Now