Resizing a CheckBox control

IfYouSaySo

Well-known member
Joined
Jan 4, 2006
Messages
102
Location
Hermosa Beach, CA
Programming Experience
3-5
More a general interest. Let's say I want to resize a Checkbox control to always be just large enough to display whatever is in Checkbox.Text. It's easy to determine the string length using Graphics.MeasureString, and it's easy to figure out what handlers to do that in. I found one example online that suggested creating a derived class from CheckBox and overriding the Paint handler to do this.

My question is, the client area is more than just the width of the Text string. It is also the width of the actual checkbox. The example I found online failed to take this into account. How do I (dynamically) calculate the width of that part?

For now, I simply added the constant 35 to the width, which is pretty close, but in the interests of being precise and correct, how would I do that?
 
If you are using .NET 2.0 (as your profile currently states) there is no need to subclass the checkbox control; simply set the standard checkbox's AutoSize property to True.
 
Back
Top