我有两块嵌在一起的分隔板。问题是,我在中间面板内呈现一个8x8平铺游戏。基本上,面板的高度和宽度需要8的奇数倍数,这样我就可以很容易地找到中间的瓷砖。
我使用的是VB.net,所以所有.net解决方案都是可以接受的:)
编辑抱歉,有点让人困惑.
我的意思是,我需要宽度和高度可以除以8。数字8乘以应该是奇数:
再编辑一次下面的数字不代表大小。它们指的是两个数字被乘以。我把它们改成了*来展示这个。以下数字既适用于高度也适用于宽度。一个数字应该是奇数,另一个是8. 8*x。
5*8 -良好
6*8 -糟糕
发布于 2011-09-11 20:23:12
你可以通过对号码做mod 2来检查某件事是否奇怪。所以就这么做吧
if number mod 2 == 1:
code for board发布于 2011-09-11 20:31:26
您说,您需要的高度和宽度可除以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 = Heighthttps://stackoverflow.com/questions/7380867
复制相似问题