如何在窗口中添加多个按钮?C#
我目前正在写一个需要商店的游戏。我计划制作一个按钮打开商店/展示所有你能买到的东西的按钮。我目前很难将按钮添加到实际窗口中。“contorls”功能没有显示为选项如何在窗口中添加多个按钮?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
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:-)