Controls disabled but not showing disabled style.

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
Is there any easy way to show a control (textbox, combobox) as if it is enabled, but not actually have it enabled? I want to show the controls as a sample which I don't want the user to be able to edit, but at the same time I don't want the controls to have the greyed out appearance which they get when disabled.
 
If you simply want to display a control but have no functionality you could draw it using the ControlPaint class.

For example...
C#:
System.Windows.Forms.ControlPaint.DrawCheckBox()
You will need to pass it a Graphics object, but that isn't too complicated.
 
Not bad. But this doesn't have any methods to draw combo boxes or textboxes. Presumably I have to build these up with a combination of the other methods? Bit of a bore.
 
Actually it can draw a combobox, its just called DrawComboButton(). As for a Textbox its just a white box with a 3d edge, hardly the most taxing thing ever to knock up. If you really can't be bothered with that, just take a screen shot, crop it with paint and add picture boxes with the controls images in.
 
Here is an alternative. In .Net 2.0, each control has a DrawToBitmap() method which renders the control offscreen to a System.Drawing.Bitmap. You can render the control to a Bitmap and display it in a PictureBox. It will look identical, but will provide no input functionality.
 
marble_eater said:
Here is an alternative. In .Net 2.0, each control has a DrawToBitmap() method which renders the control offscreen to a System.Drawing.Bitmap. You can render the control to a Bitmap and display it in a PictureBox. It will look identical, but will provide no input functionality.
Thanks, that does the trick.

Cags, you're suggestion would be possible I'm sure, but if you want to deal with things like changes in system display settings it could get to be a bit of a nightmare. Thanks anyway.
 
DrawToBitmap doesn't work for rich text boxes unfortunately, and this is one of the types of control I was hoping to do this for. If you try, you don't get any errors, but just a greyed out, empty box is drawn.
 
You are right. It is shadowed in the RichTextBox and hidden from intellisense, and when you call Control.DrawToBitmap it only does the drawing handled by Windows: an empty rectangle with a 3D border. They didn't implement it. Either they ran into problems or didn't bother to try. I fiddled with some code, but no luck. What can I say, except tough luck. You can do a screen capture of the control and show that in a picture box (using the Graphics.CopyFromScreen function). That's the best I can do for you.
 
Thanks. I don't want to do a screen capture because it will require me to show real controls somewhere on screen presumably. I don't actually need the display capabilities of the richtextbox for the purposes of the sample, so I'll just substitute an ordinary textbox to get this done.
 
Cags said:
I must admit, I'm quite intruiged as to why you want to display not functioning pictures of controls.
As part of an options dialogue form. Just to show the user what effect the choices he makes relating to display will have. It's nothing major.
 
Ahh I see that does explain your unwillingness to use simple images. An interesting idea. Personally if I was doing this I might think about using standard controls, and simply not hooking up any events to it. Obivously this would allow people to do things such as enter text in a textbox, but this just helps them get a better idea of exactly what the control will look like.
 
Back
Top