0

我试图将找到的结果输出到选项卡控件中的标签。但它根本不显示它们。有人可以看看我的代码并告诉我我做错了什么吗?谢谢你。

private void btnSearch_Click(object sender, EventArgs e)
{
    int indexResult = 0;
    string title, id;
    double price;
    string a = txtSearch.Text;

    if (Xbox360.HaveGame(a, ref indexResult))
    {
        title = Xbox360.GetTitle()[indexResult];
        Results.SetTitle(title);
        id = Xbox360.GetId()[indexResult];
        Results.SetId(id);
        price = Xbox360.GetPrice()[indexResult];
        Results.SetPrice(price);
    }

    if (Ps3.HaveGame(a, ref indexResult))
    {
        title = Ps3.GetTitle()[indexResult];
        Results.SetTitle(title);
        id = Ps3.GetId()[indexResult];
        Results.SetId(id);
        price = Ps3.GetPrice()[indexResult];
        Results.SetPrice(price);
    }

    if (Wii.HaveGame(a, ref indexResult))
    {
        title = Wii.GetTitle()[indexResult];
        Results.SetTitle(title);
        id = Wii.GetId()[indexResult];
        Results.SetId(id);
        price = Wii.GetPrice()[indexResult];
        Results.SetPrice(price);
    }

    // Basically I am going to output the result from the array Results, however, 
    // here I just want to output a sample string 
    for (int i = 0; i < 3; i++)
    {
        Label resultLabel = new Label();
        resultLabel.Location = new Point(10, 7);
        resultLabel.Text = "output is here";
        this.Controls.Add(resultLabel);
    }
}
4

3 回答 3

2

尝试将它们添加到您要在其上显示它们的 TabPage:

this.TabControl1.TabPages[0].Controls.Add(resultLabel);
于 2013-05-14T19:39:30.197 回答
1

您还应该考虑将遗产用于 Wii、Ps3 和 Xbox 类,然后您可以这样做:

foreach (GenericType console in consoleList)
{

    if (console.HaveGame(a, ref indexResult))
    {
        title = console.GetTitle()[indexResult];
        Results.SetTitle(title);
        id = console.GetId()[indexResult];
        Results.SetId(id);
        price = console.GetPrice()[indexResult];
        Results.SetPrice(price);
    }
}
于 2013-05-14T19:43:24.083 回答
0
 foreach (TabPage tab in myTabControl.TabPages)
 {
     Label lbl = new Label();
     lbl.Text = tab.Text;
     tab.Controls.Add(lbl);
 }
于 2013-05-15T01:34:15.557 回答