tags:

views:

31

answers:

2

I've my screen resolution set to 1024 x 768 pixels and the icon size is 32x32 and default icon spacing (not changed). how can I calculate possible number of desktop icons that can fit into that resolution?

A: 

Simple:

numColIcon = Screen.Width / (Icon.Width + Icon.HorizontalSpacing)
numRowIcon = Screen.height / (Icon.height + Icon.VerticalSpacing)
numTotalIcon = numColIcon * numRowIcon
Paulo Santos
numRowIcon = 768 / (32 + 43) gives 10. But I have 9 there.
Gates127
A: 

It's a little more complex actually and should be:

numColIcon = (Screen.Width-Icon.HorizontalSpacing) / (Icon.Width + Icon.HorizontalSpacing)
numRowIcon = (Screen.Height-Icon.VerticalSpacing) / (Icon.height + Icon.VerticalSpacing)
numTotalIcon = numColIcon * numRowIcon

You need to account for one more spacing which comes as the last "column" or "row". The number of padding rows and columns will always be N+1 where N is the number of object rows and columns.

The parentheses are important for proper calculation (Divide is higher precedence than minus)

In your example then:

numRowIcon = (768 - 43) / (32 + 43) will give 9 (rounded down or truncated)
Paul Sasik