Making controls read only within a group box

1,386 views
Skip to first unread message

southstander132

unread,
Mar 28, 2011, 1:06:48 PM3/28/11
to dotnetde...@googlegroups.com
Greetings,
 
I know how to loop thru controls in a groupbox and disable them, or make the entire groupbox enabled = false, but the users say they can't see the text when the fields are disabled - the color is greyed out and too light.  I can't figure out how to make these fields (text boxes, comboboxes, etc.) readonly instead.  I get the error: 
 
Error 2 'System.Windows.Forms.Control' does not contain a definition for 'Readonly' and no extension method 'Readonly' accepting a first argument of type 'System.Windows.Forms.Control' could be found (are you missing a using directive or an assembly reference?) 
 
Is there any way to do this?  Or are they just stucked with greyed out text?
 
Thanks so much in advance!

Rudion 9550XT

unread,
Mar 29, 2011, 1:58:50 AM3/29/11
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi southstander132,

You can simpy do this trick so user can see the text even the control
is disable:

textBox1.ReadOnly = true;
textBox1.ForeColor = Color.Black;
textBox1.BackColor = Color.Yellow;

Just don't use 'SystemColors' for the ForeColor or BackColor value,
because the result will be difference in difference system/OS/Theme
windows.

Regards,
Rudion9550XT


On Mar 29, 12:06 am, southstander132 <southstander...@gmail.com>
wrote:

Cerebrus

unread,
Mar 30, 2011, 3:00:09 AM3/30/11
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
You're missing the cast to the type of control you are referencing.
The Controls property lists a collection of all child controls
implicitly cast as the base Control class. The error message is
correctly telling you that the Control class does not have a ReadOnly
property.

For example,

---

private void ToggleControls(bool enabled)
{
foreach(Control ctl in MyGroupBox.Controls)
{
if (ctl is TextBox)
{
TextBox txt = ctl as TextBox;
txt.ReadOnly = enabled;
}
else if (ctl is ComboBox)
{
ComboBox cmb = ctl as ComboBox;
cmb.Enabled = enabled;
}
}
}
---

On Mar 28, 10:06 pm, southstander132 <southstander...@gmail.com>
wrote:

Lori Costanzo

unread,
Apr 2, 2011, 12:31:43 PM4/2/11
to dotnetde...@googlegroups.com, Cerebrus
That's exactly what I couldn't figure out how to do - thanks much - worked like a charm and I am moving forward!

--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to dotnetde...@googlegroups.com
To unsubscribe from this group, send email to
dotnetdevelopm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net

Cerebrus

unread,
Apr 3, 2011, 12:23:13 PM4/3/11
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Most welcome! Have a good one ! :-)
> > Groups "DotNetDevelopment, VB.NET <http://vb.net/>, C# .NET, ADO.NET<http://ado.net/>,
> > ASP.NET <http://asp.net/>, XML, XML
> > Web Services,.NET Remoting" group.
> > To post to this group, send email to dotnetde...@googlegroups.com
> > To unsubscribe from this group, send email to
> > dotnetdevelopm...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
> > or visit the group website athttp://megasolutions.net- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages