为ComboBox指定显示整型标签
本文关键字:整型 标签 显示 ComboBox | 更新日期: 2023-09-27 17:53:29
嘿,我是soft的新手,但一直在使用它来帮助自己。无论如何,我一直在尝试让我的组合框中的项目在我的Race标签中显示一个int。Else可以工作,由于某种原因,当我单击列表中的第二个项目时,它将StrRaceLbl更改为1,但没有其他更改。不管怎么说,我没有办法了,我查了所有我能查到的东西,试图弄清楚这个问题。任何信息都有帮助!谢谢。
private void RaceCmbBx_SelectedIndexChanged_1(object sender, EventArgs e)
{
int num1, num2, num0;
int index = RaceCmbBx.SelectedIndex;
num1 = 1;
num2 = 2;
num0 = 0;
if (index == 1)
{
StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ChaRaceLbl.Text = (Convert.ToInt32(num0)).ToString();
}
if (index == 2)
{
StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ChaRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
}
else
StrRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
DexRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
ConRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
WisRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
IntRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
ChaRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
}
这也是我用来添加项目到组合框:
// Content item for the combo box
private class Item
{
public string Name;
public int Value;
public Item(string name, int value)
{
Name = name; Value = value;
}
public override string ToString()
{
// Generates the text shown in the combo box
return Name;
}
}
public Ch_Creation()
{
InitializeComponent();
// Put some stuff in the combo box
RaceCmbBx.Items.Add(new Item("Dragonborn", 1));
RaceCmbBx.Items.Add(new Item("Dwarf", 2));
RaceCmbBx.Items.Add(new Item(" Hill Dwarf", 3));
}
private void RaceCmbBx_SelectedIndexChanged(object sender, EventArgs e)
{
// Display the Value property
Item itm = (Item)RaceCmbBx.SelectedItem;
Console.WriteLine("{0}, {1}", itm.Name, itm.Value);
}
p。S是的,这是D&D
看起来你漏掉了一对大括号和一个额外的if语句(如果我没记错的话)
private void RaceCmbBx_SelectedIndexChanged_1(object sender, EventArgs e)
{
int num1, num2, num0;
int index = RaceCmbBx.SelectedIndex;
num1 = 1;
num2 = 2;
num0 = 0;
if (index == 1)
{
StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ChaRaceLbl.Text = (Convert.ToInt32(num0)).ToString();
}
else if (index == 2)
{
StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
ChaRaceLbl.Text = (Convert.ToInt32(num1)).ToString();
}
else
{
StrRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
DexRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
ConRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
WisRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
IntRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
ChaRaceLbl.Text = (Convert.ToInt32(num2)).ToString();
}
}
好了,谢谢大家的帮助!我重新修改了代码,现在好像可以运行了。谢谢你的帮助。
private void RaceCmbBx_SelectedIndexChanged_1(object sender, EventArgs e)
{
int num1, num2, num0;
int index = RaceCmbBx.SelectedIndex;
num1 = 1;
num2 = 2;
num0 = 0;
if (index == 0)
{
StrRaceLbl.Text = num1.ToString();
DexRaceLbl.Text = num1.ToString();
ConRaceLbl.Text = num1.ToString();
WisRaceLbl.Text = num1.ToString();
IntRaceLbl.Text = num1.ToString();
ChaRaceLbl.Text = num1.ToString();
}
else if (index == 1)
{
StrRaceLbl.Text = num2.ToString();
DexRaceLbl.Text = num1.ToString();
ConRaceLbl.Text = num2.ToString();
WisRaceLbl.Text = num1.ToString();
IntRaceLbl.Text = num1.ToString();
ChaRaceLbl.Text = num2.ToString();
}
else
{
StrRaceLbl.Text = num2.ToString();
DexRaceLbl.Text = num0.ToString();
ConRaceLbl.Text = num1.ToString();
WisRaceLbl.Text = num0.ToString();
IntRaceLbl.Text = num1.ToString();
ChaRaceLbl.Text = num0.ToString();
}
}