Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox caption and size of checkbox

Status
Not open for further replies.

Webrookie

Programmer
May 18, 2000
112
US
I'm creating checkboxes on the fly and, unfortunately, there is no autosize property. The caption I assign to each checkbox varies in length and I'd like to make the width of the checkbox so that it fits snug with the caption.
Right now I'm taking the length of the caption * 5...and that holds off fine, but when I get longer captions, the width of the checkbox gets longer and I don't want any scrollbars......

thanks in advance
 
It's true that the caption of a check box is difficult to control. One solution is to NOT use the check box caption, but use a TLabel instead (as it gives you more control).

Otherwise, you can use your form's canvas to calculate the width of the text you are displaying:
MyForm.Canvas.TextLength(sCaption);

Use this value plus the width of your check box plus about 6 pixels of white space to set the overall width of your check box control.

NOTE:
Canvas.TextLength is based on the Canvas.Font property. Make sure the Font properties of the canvas match your check box font. (Normally it will, as ParentFont = True is defaulted on Check Boxes at creation time).
 
I have considered the label method......but I don't think I want to go that route...I will mess with the form canvas...thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top