I couldn't quite figure out why it works in one instance and not
another...but if you instead set the BackColor when you change
readonly(after you do base.ReadOnly = value) it will work.
> We have currently several enhanced versions of .NET controls (textbox,
> combobox checkbox label etc) so that they automtically comform to our
[quoted text clipped - 139 lines]
>
> }
el_sid - 01 Jul 2005 10:28 GMT
Thanks for the help, that worked.
> I couldn't quite figure out why it works in one instance and not
> another...but if you instead set the BackColor when you change
[quoted text clipped - 143 lines]
> >
> > }
Hi el_sid,
Thanks for your post.
Yes, I think Robert is correct. When we set TextBox to readonly,
TextBox.BackColor will be ignored with Painting.
This is a known issue, which is documented in our internal database.
Actually, .Net TextBox is a simple wrapper of Win32 Edit control, and it
passes the painting issue to the Win32 Edit control. If we use Reflector to
view TextBox.ReadOnly property, we can see that:
public void set_ReadOnly(bool value)
{
if (this.textBoxFlags[TextBoxBase.readOnly] != value)
{
this.textBoxFlags[TextBoxBase.readOnly] = value;
if (base.IsHandleCreated)
{
base.SendMessage(0xcf, value ? -1 : 0, 0);
}
this.OnReadOnlyChanged(EventArgs.Empty);
}
}
Note: 0xcf stands for EM_SETREADONLY message.
So when we set TextBox to readonly, it simply set TextBox to readonly
state.
However, when the textbox is in readonly state, the system is drawing the
text box and it determins the background color.
To workaround this issue, we can just re-set BackColor in the ReadOnly
property(after base.ReadOnly calling), then it will override windows's
coloring.
public new bool ReadOnly
{
get
{
return(base.ReadOnly);
}
set
{
base.ReadOnly = value;
this.BackColor=SystemColours.gcolReadOnlyBackground;
// Refresh the control so the background colour is set correctly.
this.Refresh();
}
}
===============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
el_sid - 01 Jul 2005 10:28 GMT
Thanks for the help that worked.
> Hi el_sid,
>
[quoted text clipped - 57 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 04 Jul 2005 03:08 GMT
You are welcome
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.