C# 显示所选ListBoxItem';标签上的值

C# 显示所选ListBoxItem';标签上的值,c#,winforms,C#,Winforms,我正在创造一种Windows形式的“游戏”,你可以说是关于人类进化的。我创建了一个代码,在按下Add按钮时生成一个随机部落成员: public void addpop_Click(object sender, EventArgs e) { Random rand = new Random(); RandomName = rand.Next(Database.tribalage_Names.Length); //creates random name

我正在创造一种Windows形式的“游戏”,你可以说是关于人类进化的。我创建了一个代码,在按下Add按钮时生成一个随机部落成员:

    public void addpop_Click(object sender, EventArgs e)
    {
        Random rand = new Random();
        RandomName = rand.Next(Database.tribalage_Names.Length); //creates random name for pop.
        RandomSex = rand.Next(Database.sex.Length); //chooses a random sex for pop.
        RandomStartingAge = rand.Next(16, 34); //selects a random age for pop.
        RandomLevel = rand.Next(0, 5); //generates a random skill level for pop.


        if (Settings.TribePopulation <= 6) //creates the randomly generated human.
        {
            Human startinghuman = new Human(1, Database.tribalage_Names[RandomName], Database.sex[RandomSex], RandomStartingAge, RandomLevel, RandomLevel, RandomLevel, RandomLevel, RandomLevel, 100, "healthy", "curious of surroundings", "desire to create a shelter", "normal", "neutral");
            lb_poplist.Items.Add(startinghuman.Name); //adds the created human to a list.
        }

我非常希望能够随机生成这些人类对象,并且能够查看我在列表中生成的特定对象的所有int和字符串。我被难住了

根据您的设置方式,这可能会起作用:
(lb_poplist.SelectedItem as Human)
事实上,我上面的评论只有在您将lb_poplist.Items.Add(startinghuman.Name)更改为lb_poplist.Items.Add(startinghuman)并设置
myListBox.DisplayMember=“Name”
@CodingYoshi此操作有效!!你是最棒的!非常感谢。这将为我省去很多麻烦。你还应该有
Random rand=new Random()在窗体级别,而不是在事件处理程序内部。
 public void viewpop_Click_1(object sender, EventArgs e)
    {
        tb_popname.Text = lb_poplist.SelectedItem.ToString(); //This works in showing the human's name.
        lbl_humanage.Text = lb_poplist.SelectedItem??????? //THIS is what im stumped on. Getting the age of the created human, and turning that int into the value of this label.

    }