I help someone transform a huge mess of panels and 700 carefully set flags with something more sensible. My plan is to implement a custom control that uses the ControlPaint class to draw checkboxes manually; this will simplify the work with data and discard 700 GDI descriptors from the form, probably will be a good thing *.
ControlPaint.DrawCheckbox () accepts Graphics, Borders for checkbox and ButtonState. The ratings seemed interesting; I thought it could be:
- If I provide too much space, I get a flag concentrated within these limits.
- I get a checkbox in the size specified by me.
So, I tested a 100x100 rectangle for borders and found that as a result, the 100x100 checkbox was selected. Interesting! However, I just need a simple old checkbox that displays with the default size for the default installation. I expected this to be a call to some API function such as GetSystemMetrics (), but I'm not sure if something stands out as the right way. (Perhaps SM_CXMENUCHECK? It only seems like a coincidence.)
CheckBoxRenderer displays the desired size. I am going to use this, but I don’t like not knowing how to do something. So I reached out with Reflector to see what it was doing. If you render with some kind of visual style, it calls GetThemePartSize (), which is a rather complicated API call, but at least answers how I can get the size for the visual theme. Interestingly, if visual styles are not used, it seems that it returns a hard code: 13x13. Is the cell size of the system really hardcoded to 13 pixels square or is it just lazy control by MS?
- CheckBoxRenderer. . , , Reflector, , -, .
* , 700 - , . 2 . DataGridView , . - , , .