0

我有几个嵌套在彼此内部的拆分面板。问题是,我在中心面板内渲染了一个 8x8 平铺游戏。基本上,面板的高度和宽度需要是 8 的奇数倍,以便我可以轻松找到显示的中心图块。

我正在使用 VB.net,所以所有 .net 解决方案都是可以接受的 :)

编辑对不起,这有点令人困惑......

我的意思是,我需要宽度和高度可以被 8 整除。数字 8 乘以应该是奇数:

再次编辑下面的这些数字不是指尺寸。它们指的是两个数字相乘。我已将它们更改为 * 以显示这一点。下面的这些数字适用于高度和宽度。一个数字应该是奇数,另一个是 8. 8*x

5*8 - 好

6*8 - 不好

4

2 回答 2

1

您可以通过对数字执行 mod 2 来检查是否有异常。所以就这样做

if number mod 2 == 1:
   code for board
于 2011-09-11T20:23:12.420 回答
0

您说您需要高度和宽度都可以被 8 整除,但在您的示例中,只有高度可以被它整除。无论如何,这是一种方法:

将其放入调整大小事件处理程序中:

Dim Height as Integer = SplitControl1.Panel1.Width
    If Height mod 8 <> 0 then
  Height -= (Height mod 8)
End If

Height += 9 //This ensures that the Height is not 0 and still is divisible by 8 + 1 (to be odd)

Dim Width as Integer = SplitControl1.Panel1.Width
If Width mod 8 <> 0 then
   Width -= (Width mod 8)
End If

Width += 9 //This ensures that the Width is not 0 and still is divisible by 8 + 1 (to be odd)

最后

SplitControl1.Panel1.Width = Width
SplitControl1.Panel1.Height = Height
于 2011-09-11T20:31:26.263 回答