我试图将已找到的结果输出到标签控件中的标签。但它根本不显示它们。有人请看看我的代码并告诉我我做错了什么?谢谢。
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);
}
}
答案 0 :(得分:2)
尝试将它们添加到要在其上显示的TabPage中:
this.TabControl1.TabPages[0].Controls.Add(resultLabel);
答案 1 :(得分: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);
}
}
答案 2 :(得分:0)
foreach (TabPage tab in myTabControl.TabPages)
{
Label lbl = new Label();
lbl.Text = tab.Text;
tab.Controls.Add(lbl);
}