Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在窗口中添加多个按钮?C#_C#_Button_Controls - Fatal编程技术网

如何在窗口中添加多个按钮?C#

如何在窗口中添加多个按钮?C#,c#,button,controls,C#,Button,Controls,我目前正在写一个需要商店的游戏。我计划制作一个按钮打开商店/展示所有你能买到的东西的按钮。我目前很难将按钮添加到实际窗口中。“contorls”功能没有显示为选项 for (int i = 0; i < weaponsList.Count; i++) { Button newButton = new Button(); newButton.Name = Convert.ToString(i); newB

我目前正在写一个需要商店的游戏。我计划制作一个按钮打开商店/展示所有你能买到的东西的按钮。我目前很难将按钮添加到实际窗口中。“contorls”功能没有显示为选项

for (int i = 0; i < weaponsList.Count; i++)
        {
            Button newButton = new Button();
            newButton.Name = Convert.ToString(i);
            newButton.Content = weaponsList[i].WeaponName += weaponsList[i].MinDamage += weaponsList[i].MaxDamage += weaponsList[i].Cost;
            newButton.Visibility = Visibility.Visible;
            newButton.Width = 502;
            newButton.Height = 78;
        }
for(int i=0;i

for循环是这样的,它将不断为武器数量添加按钮。我试过做控制的事情,但没有成功

将所有按钮放在同一位置。如果要查看所有按钮,则必须具有不同的位置。快速好的解决方案在这里:

for (int i = 0; i < weaponsList.Count; i++)
{
  Button newButton = new Button();
  newButton.Name = Convert.ToString(i);
  newButton.Content = weaponsList[i].WeaponName += weaponsList[i].MinDamage += weaponsList[i].MaxDamage += weaponsList[i].Cost;
  newButton.Visibility = Visibility.Visible;
  newButton.Width = 502+10*i;
  newButton.Height = 78+10*i;
}
for(int i=0;i
将所有按钮放在同一位置。覆盖较低的按钮?使用:this.Controls.Add(newButton);别忘了使用tablelayoutpanel:-)