Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
Posted

If you simply want to display a control but have no functionality you could draw it using the ControlPaint class.

 

For example...

System.Windows.Forms.ControlPaint.DrawCheckBox()

You will need to pass it a Graphics object, but that isn't too complicated.

Anybody looking for a graduate programmer (Midlands, England)?
Posted
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.
Posted
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.
Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]
Posted
Here is an alternative. In .Net 2.0' date=' 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.[/quote']

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.

Posted
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.
  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]
Posted
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.
Posted
I must admit, I'm quite intruiged as to why you want to display not functioning pictures of controls.
Anybody looking for a graduate programmer (Midlands, England)?
Posted
I must admit' date=' I'm quite intruiged as to why you want to display not functioning pictures of controls.[/quote']

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.

Posted
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.
Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...