المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Automatically sizing a button based off data source



C# Programming
06-03-2009, 06:12 PM
Sorry for the indescriptive title in advance, I figured that is what suited the problem at hand best.

I'm creating a menu based off a data source and dynamically adding buttons. The width of the menu should be set by the 'longest' string that is to be displayed on any of the buttons, so my question is how do i know what size to set my button to based off of the text to be displayed?

An example of such would be the following string array:

"Help"
"Option 1"
"This is a longer option"

All buttons should be set to have a width wide enough to display "This is a longer option" so that all menu buttons have an equal width. My question, how do I translate that string of text into a width in pixels to resize my button to?

If my problem is not descriptive or clear enough, sorry in advance and I'd be happy to clear anything up. Thanks for the view in advance.

Check out the CodeProject forum Guidelines (http://www.codeproject.com/KB/scrapbook/ForumGuidelines.aspx)[^ (http://www.codeproject.com/KB/scrapbook/ForumGuidelines.aspx)]