Enable/Disable Windows Forms Controls 
Author Message
 Enable/Disable Windows Forms Controls

I must be missing something.  All I want to do is disable
a set of controls on my (Windows .Net) form at certain
times.  They are mostly TextBoxes and ComboBoxes.  When
disabled, these controls will contain valid information
that the user needs to see.  The problem is that my user
doesn't like the color combination of the disabled
controls (if the text would remain Black, it would be
fine).  Is there a reasonably simple way to do this?  I
have tried a number of approaches, but none works well.  I
need a way do accomplish this without referencing each
control by specific name.  Using the ReadOnly property
would solve the problem, but this property is not
available for ComboBoxes, and not available in the
collection of controls, as follows:

for each Control in Container
  Control.Enabled = False  ' works fine, but bad colors
  Control.ReadOnly = True  ' fails -- no such animal

Is there a way to change the color settings for a disabled
control?  That would be the easiest way to handle this.

I've also tried emulating the ReadOnly behavior in a Sub
by capturing and rejecting keyboard characters when the
controls should not be available.  It would have worked
beautifully, but for some crazy reason the "Delete" key
does not raise the KeyPress event.  By the way, what's up
with that?  How can a certain key not get trapped by the
KeyPress event?

Anyway, I'm about out of things to try.  Anybody got a
good idea for me?

Thanks much.

Wed, 02 Mar 2005 02:23:07 GMT  
 Enable/Disable Windows Forms Controls

> Is there a way to change the color settings for a disabled
> control?  That would be the easiest way to handle this.

I'm afraid there is no easy way to do this because the color is a
setting of system. You can go to the Display applet in the Control
Panel to change it. But, this affects all the controls.

Peter Wu
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no

Sat, 05 Mar 2005 14:18:27 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Enable/Disable user controls in Windows Form

2. Disable/Enable a NIC in Windows 2000

3. Disable/Enable a NIC in Windows 2000

4. Enable and Disable Windows

5. Disable/Enable a NIC in Windows 2000

6. How do you conditionally disable/enable a field on a form

7. I cant disable/enable my form!!??

8. How do I enable and disable menu items on the parent form

9. disabling the DISABLE/ENABLE macros menu on opening spreadsheet

10. disable the enable/disable macro message

11. enable/disable menu controls Access97

12. Enable/Disable controls using VBScript


Powered by phpBB® Forum Software