TextBoxEx: You can't set ReadOnly and BackColor

  • Thread starter Thread starter Kris
  • Start date Start date
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
 
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;
}
}
 
Back
Top