Preventing textBox from getting focus ?

O

ORC

Does anyone have an idea on how to prevent a textbox from getting focus i.e.
the same function as "textBox.enabled = false" but without making the text
written in gray ?

This code works:
private void textBox1_GotFocus(object sender, System.EventArgs e)
{
textBox1.Parent.Focus(); // the form got the focus instead
}
but I would prefer to make a new control - let's call it an indicator, that
implements the above functionality.

Thanks!
Ole
 
G

Guest

ORC said:
Does anyone have an idea on how to prevent a textbox from getting focus i.e.
the same function as "textBox.enabled = false" but without making the text
written in gray ?

This code works:
private void textBox1_GotFocus(object sender, System.EventArgs e)
{
textBox1.Parent.Focus(); // the form got the focus instead
}
but I would prefer to make a new control - let's call it an indicator, that
implements the above functionality.

Thanks!
Ole
Hi,

Just create a custom control that inherits from the textbox control, and
override the GotFocus event within the control with your new code.

Check here for a nice tutorial on creating controls:
http://www.c-sharpcorner.com/Code/2003/May/InheritedControls.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top