Creating custom textbox

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
 
P

Peter Foot [MVP]

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
 
M

Maarten Struys eMVP

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
 

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