0

我有一个我实例化Character的类的对象数组( )PlayerForm1

我需要以另一种形式(Combat)使用这些对象,但我不确定如何传递它们。这是我尝试过的:

public partial class Form1: Form
 private void combatBtn_Click(object sender, EventArgs e)
    {
        Form combat = new Combat(Character[0-9]);

        combat.ShowDialog();

    }

public partial class Combat : Form
  {

    Player[] character = new Player[9];

    public Combat(Player chars[0-9])
    {
        InitializeComponent();

        for (int i = 0; i > 9; i++)
        {
            character[i] = chars[i];
        }
    }
4

1 回答 1

5

您可以将属性添加到Combat父表单并从其设置:

public partial class Combat : Form
{
    public Player[] Characters { get; set; }
}

然后您可以在创建表单时设置该属性:

private void combatBtn_Click(object sender, EventArgs e)
{
    Combat combat = new Combat();
    combat.Characters = somePlayerArray;

    combat.ShowDialog();
}
于 2013-01-14T16:59:49.700 回答