lundi 23 février 2015

C# WinForms 4-sate checkbox

Using VS2013, C#.NET 4.5, and WinForms. Migrating to WPF is not an option at this point.


The standard checkbox control handles 2-state and 3-state modes, but I need a 4-state checkbox. I can't find a 4-state checkbox library on the net anywhere, so I'm assuming I'll have to make one (if y'all know of one, that'd be great).


I have a set of four PNGs as draft images of the checkbox appearance, and I have played around with just painting those on a button and having the button_click event cycle through which image is displayed and update the data value. This doesn't seem to scale the image with the button well, though, and it feels kludgy to load static bitmaps instead of vector drawing the images so they're always to scale.



  • Is there a way to inherit from the checkbox control itself and add a fourth state?

  • If so, where do I go to override how the states are drawn? I need to do it "correctly" so that if the form is Scaled, the checkbox doesn't end up looking all bitmap-nasty.

  • I'm not even sure what keywords to use to search for how to do the actual drawing.


Background: I'd generally consider this to be a nasty UI choice, but I'm making a program that saves, loads, and displays a "World of Darkness" character sheet of any arbitrary system, and the WoD games use a 4-state injury that's represented on the sheet by an empty box, a box with one slash across it, a box with an X across it, or a box with a 4-stroke asterix across it (optionally, a filled box).


For the moment I'm going with matching the original with high fidelity; later, as an option, I'll let the user switch to radio buttons to support my own preference.


This is my first real exploration of GUI programming beyond the basics, so I'm not sure quite how to proceed.





Aucun commentaire:

Enregistrer un commentaire