【问题标题】:How to add multiple buttons to a window? C#如何在一个窗口中添加多个按钮? C#
【发布时间】:2015-10-11 08:10:33
【问题描述】:

我目前正在编写一个需要商店的游戏。我计划制作 1 个按钮打开商店/显示您可以购买的所有东西的按钮。我目前很难将按钮添加到实际窗口。 “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 循环是为了不断添加武器数量的按钮。我试过做控制的事情,但没有奏效。

【问题讨论】:

  • 你把所有的按钮都放在同一个位置。你遮住了下面的按钮?
  • 使用:this.Controls.Add(newButton);不要忘记使用 tablelayoutpanel :-)

标签: c# button controls


【解决方案1】:

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

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;
}

【讨论】:

    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多