C# 如何制作一个按钮数组,并将其放在与数组大小匹配的面板上?
我正在用C#做一个扫雷游戏,只需要生成一个按钮数组,然后把这个数组放到一个面板中。但阵列大小会根据难度而变化,例如,在介质中为easy 8x8、16x16。如何根据难度生成此矩阵,并根据阵列的大小(尺寸)调整面板(或窗口)的大小,从而访问每个按钮[I,j]?C# 如何制作一个按钮数组,并将其放在与数组大小匹配的面板上?,c#,arrays,winforms,C#,Arrays,Winforms,我正在用C#做一个扫雷游戏,只需要生成一个按钮数组,然后把这个数组放到一个面板中。但阵列大小会根据难度而变化,例如,在介质中为easy 8x8、16x16。如何根据难度生成此矩阵,并根据阵列的大小(尺寸)调整面板(或窗口)的大小,从而访问每个按钮[I,j]?public button[][]InitButtonArray(int width,int height) public Button[][] InitButtonArray(int width, int height) {
public button[][]InitButtonArray(int width,int height)
public Button[][] InitButtonArray(int width, int height)
{
Button[][] btnArr = new Button[width][];
for (int x = 0; x < width; x++)
{
btnArr[x] = new Button[height];
for (int y = 0; y < height; y++)
{
btnArr[x][y] = new Button();
}
}
return btnArr;
}
public void AdjustPanelSize(Panel panel,int buttonWith, int buttonHeight, int width, int height)
{
panel.Size = new Size(buttonWith * width, buttonHeight * height);
}
{
按钮[][]btnArr=新按钮[宽度][];
对于(int x=0;x
谢谢您的回答。让我们看看我是否理解正确,在InitButtonArray(int-width,int-height)
中,我传递了数组的大小。在调整面板大小(面板面板、int按钮WITH、int按钮height、int宽度、int高度)中,我传递创建的面板、每个按钮的大小以及面板的大小,对吗?您显然也必须注册单击事件,并将一些自定义数据与按钮关联,以便确定其行和列。@Jefferson buttonWidth是按钮的宽度,ButtonHight是按钮的高度,width是x方向的按钮数,height是y方向的按钮数。