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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing label and form sizes on the fly 1

Status
Not open for further replies.

KornGeek

Programmer
Aug 1, 2002
1,961
US
I am attempting to create a form that mimics the functionality of the msgbox command, but supports a time out as well. I want to be able to pass this form the message, buttons, title (as in the msgbox command), and a timeout. So far, everything is working, except that I can't get the form to resize itself to fit the text.

The msgbox command brings up a message box that is suitably wide to fit the text, and the OK button is centered. Is there any way that I can get a regular form to do this?

Thanks.
 
Hi,

Have you got 'autoresize' set for the form?

If so, are you using a label to display the message?
If so, try using a textbox (formatted to look like a label) with it's <Can Grow> property set to true.

Hope this helps.

Regards,

Darrylle &quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot; darrylles@totalise.co.uk
 
Darrylle,
I already had autoresize set to true for the form. I tried converting the label to a text box, and setting the CanGrow property for both the control and the detail section to true. I also tried setting up a table as a data source for the text box. None of these worked, but I appreciate your ideas. Do you have any other suggestions?

Thank you.
 
Hi,

Off the top of my head:

Get the length of the string to be displayed (using Len())and use the Form.Width property to adjust the form size manually dependant on the length of the string.

Sorry.

Regards,

Darrylle

&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot; darrylles@totalise.co.uk
 
I was thinking of something along these lines. Do you know of any place where I can find the approximate width of each character? I'm using the 8 point Tahoma font, which matches the system's message boxes. The len() function gives me the number of characters, but I can't figure out how to convert this.

I appreciate all of the help you're giving me.
 
Hi,

My tack would be: first display a string that 'centralizes' on form. (Gaps between edges of form are equal).

Increase the length of string by x number of characters.
Keep manually increasing width of form until gaps between edges of form are again equal.

This will give a 'rough' idea of ratio to use.

regards,

Darrylle







&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot; darrylles@totalise.co.uk
 
Darrylle,
The way I tested for character size is to populate the underlying table with a string longer than what would fit in the text box, and then count the number of characters that appeared when I set the width of the text box to various lengths (a variation on your suggestion).

Taking 8 counts with each of my text strings, I got an overall average of about 0.054 inches per character. The text I used was the following:

&quot;Now is the time for all good men to come to the aid of their country.&quot;
Average: 0.050 inches per character

&quot;The quick brown fox jumps over the lazy dog.&quot;
Average: 0.049 inches per character

A brief passage from MacBeth
Average: 0.058 inches per character

Lyrics to a Korn song (without spaces)
Average: 0.059 inches per character

Same lyrics with spaces
Average: 0.053 inches per character

If I assume 0.055 inches per character, that should be adequate. If I find I'm getting errors, I'll just adjust this value.

Thanks for all of your help walking me through this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top