嘿,我是SOF的新手,但一直在用它来帮助自己。无论如何,我一直试图让我的Combobox项目在我的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();
}
这也是我用来向ComboBox添加项目的内容:
// 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
答案 0 :(得分:0)
看起来你错过了几个大括号和一个额外的if语句(如果我记得D& D角色创作正确的话:) :( / p>
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();
}
}
答案 1 :(得分:0)
好吧伙计感谢您的帮助!我重新启动了代码,它现在似乎正在运行。我很感激你的帮助。
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();
}
}