TextBoxEx: You can't set ReadOnly and BackColor

K

Kris

I'm using the OpenNetCf's TextBoxEx control and I need the textbox to be
ReadOnly and I also need to change the BackColor property. However, the
control seems to overide the BackColor property when the ReadOnly value
is set.

Does anyone know how to change the BackColor of a textbox when the
ReadOnly propery is set?

Kris
 
K

Kris

In article <[email protected]>, kris@omni-
ts.com says...

I found a work around for this. Although it's not possible to set the
BackColor property (and have the color actually show) when the ReadOnly
property is set on a TextBox. You can create a class that inherits from
TextBox and overides the OnKeyPress event. During the OnKeyPressEvent
you could then check a boolean property you created on the control
(IsReadOnly for example) and simply ignore the key press if appropriate
(essentially making it ReadOnly).


public class TextBoxKd : TextBox
{
public TextBoxKd(){}

private bool isRead = false;
public boolean IsReadOnly
{
get{return this.isRead;}
set{this.isRead = value}
}

protected override void OnKeyPress
(System.Windows.Forms.KeyPressEventArgs e)
{
if(!this.IsReadOnly)
base.OnKeyPress(e);
e.Handled = true;
}
}
 

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