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

Programatically space/center buttons (controls)?

Status
Not open for further replies.

cjtaylor

Programmer
Aug 12, 2001
69
0
0
US
Hello,

I have a bunch dynamically created buttons which are placed in a tabpage. Not all the buttons are created all the time, so what I want to do is space them equally and center them in the container which they reside programatically, like the designer does at design time. I was wondering if there is an easy way to do this?

Any hints?
 
Assuming they're all the same width, the formula to calculate the inter-control spacing would be:

[tt]spacing = (availablewidth - (n * controlwidth)) / (n + 1)[/tt]

The first control would start at [tt]spacing / 2[/tt], and each subsequent one would be [tt]spacing + controlwidth[/tt] further along.

Don't forget to test for the case where there's more controls than can fit in the available space ([tt]spacing[/tt] will be < 1).

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top