Creating custom textbox

  • Thread starter Thread starter samskas
  • Start date Start date
S

samskas

Hi frnd,

Can u suggest me how to create a textbox with readonly
property without changing its look and feel apperance(as
the bcak color changes to shady) ?
Any suggestion or tip would be of great help.

Thanx
 
A quick trick is to handle the GotFocus event on the textbox and set the
focus elsewhere - e.g. the parent form, so the user cannot position the
cursor in the box and overtype:-

private void textBox1_GotFocus(object sender, System.EventArgs e)
{
textBox1.Parent.Focus();
}

Peter
 
Here is something that might help you (I have not actually
tried it, since I am not in front of a development machine
right now). If you just eat the keypress events the
textbox is not accepting characters while remaining its
original look. In this case you should leave the ReadOnly
property to false.

textBox1.KeyPress = new KeyPressEventHandler
(TextBox_KeyPress);

....

protected void TextBox_KeyPress(KeyPressEventArgs e)
{
// eat the event but don't take further action.
e.Handled = true;
}

Regards,
Maarten Struys, eMVP
PTS Software bv
 
Back
Top