c#转到测验的下一页
你好,我很难在我的测验中转换到下一个问题c#转到测验的下一页,c#,arrays,visual-studio-2010,C#,Arrays,Visual Studio 2010,你好,我很难在我的测验中转换到下一个问题 private void Form1_Load(object sender, EventArgs e) { Random random = new Random(); int Month = random.Next(0); if (Month == 0) { radioButton1.Text = "January"; radi
private void Form1_Load(object sender, EventArgs e)
{
Random random = new Random();
int Month = random.Next(0);
if (Month == 0)
{
radioButton1.Text = "January";
radioButton2.Text = "April";
radioButton3.Text = "August";
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\1. Enero – January.Wav");
simpleSound.Play();
}
if (Month == 1)
{
radioButton1.Text = "July";
radioButton2.Text = "December";
radioButton3.Text = "February";
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\2. Febero – February.Wav");
simpleSound.Play();
}
if (Month == 2)
{
radioButton1.Text = "May";
radioButton2.Text = "September";
radioButton3.Text = "March";
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\3. Marzo – March.Wav");
simpleSound.Play();
}
if (Month == 3)
{
radioButton1.Text = "April";
radioButton2.Text = "August";
radioButton3.Text = "March";
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\4. Abril – April.Wav");
simpleSound.Play();
}
if (Month == 4)
{
radioButton1.Text = "March";
radioButton2.Text = "May";
radioButton3.Text = "November";
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\5. Mayo – May.Wav");
simpleSound.Play();
}
if (Month == 5)
{
radioButton1.Text = "July";
radioButton2.Text = "June";
radioButton3.Text = "February";
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\Callum\Documents\My Projects (Dissertation)\App sounds and pictures\Unit 8 Months (Complete)\Audio\6. Junio – June.Wav");
simpleSound.Play();
}
static int i = 0;
private void button1_Click(object sender, EventArgs e)
{
Random random = new Random();
int Month = random.Next(0);
if (Month == 0)
if (radioButton1.Checked)
{
label1.Text = "Correct";
radioButton2.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton2.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton3.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
if (Month == 1)
if (radioButton1.Checked)
{
label1.Text = "Incorrect";
radioButton2.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton2.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton3.Checked)
{
label1.Text = "Correct";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
if (Month == 2)
if (radioButton1.Checked)
{
label1.Text = "Incorrect";
radioButton2.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton2.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton3.Checked)
{
label1.Text = "Correct";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
if (Month == 3)
if (radioButton1.Checked)
{
label1.Text = "Correct";
radioButton2.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton2.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton3.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
if (Month == 4)
if (radioButton1.Checked)
{
label1.Text = "Incorrect";
radioButton2.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton2.Checked)
{
label1.Text = "Correct";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton3.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
if (Month == 5)
if (radioButton1.Checked)
{
label1.Text = "Incorrect";
radioButton2.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton2.Checked)
{
label1.Text = "Correct";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
else if (radioButton3.Checked)
{
label1.Text = "Incorrect";
radioButton1.Enabled = false;
radioButton3.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
radioButton1.text = Month[i];
radioButton2.text = Month[i];
radioButton3.text= Month[i];
i = (i + 1) % 5;
}
出现3个错误,说明“'System.Windows.Form.RadioButton'不包含'text'的定义,并且找不到接受第一个参数类型'System.Windows.Forms.RadioButton'的扩展方法'text'(是否缺少using指令或程序集引用)
我不熟悉这一点,正在尝试自学c#,所以请耐心等待,提前谢谢。c#区分大小写。您要查找的属性是文本,而不是文本
private void button2_Click(object sender, EventArgs e) {
radioButton1.Text = Month[i];
radioButton2.Text = Month[i];
radioButton3.Text= Month[i];
i = (i + 1) % 5;
}
C#区分大小写。您要查找的属性是文本,而不是文本
private void button2_Click(object sender, EventArgs e) {
radioButton1.Text = Month[i];
radioButton2.Text = Month[i];
radioButton3.Text= Month[i];
i = (i + 1) % 5;
}
罗德里戈的回答补充道:
private void button2_Click(object sender, EventArgs e) {
radioButton1.Text = Month[i];
radioButton2.Text = Month[i];
radioButton3.Text= Month[i];
i = (i + 1) % 5;
}
这里您试图将文本属性(字符串)设置为和整数(月)
尝试:
此外,每个单选按钮都有相同的文本(月号)。不确定这是否是有意的
此外,在本例中,在检查当前月份时,应使用if else
或switch
语句,而不是if
块。当前,如果month==1
,则仍将不必要地对照2、3、4等进行检查
最后,考虑将随机数的生成限制为a</p>,加上罗德里戈的回答:
private void button2_Click(object sender, EventArgs e) {
radioButton1.Text = Month[i];
radioButton2.Text = Month[i];
radioButton3.Text= Month[i];
i = (i + 1) % 5;
}
这里您试图将文本属性(字符串)设置为和整数(月)
尝试:
此外,每个单选按钮都有相同的文本(月号)。不确定这是否是有意的
此外,在本例中,在检查当前月份时,应使用if else
或switch
语句,而不是if
块。当前,如果month==1
,则仍将不必要地对照2、3、4等进行检查
<>最后,考虑把随机数的创建限制到.< /p>,你能简化你的问题吗?似乎太长了,你能简化你的问题吗?似乎太长的欢呼了,但是它仍然没有改变页面。当我点击“Null ReavigyExcExchange是未处理的”按钮时,它出现了一个错误。对象引用未设置为对象的实例。“有什么想法吗???@callum-这是因为变量Month
超出范围。它是在另一个方法中定义的。将其定义为类的字段,而不是方法。欢呼声确实有帮助,但仍然没有更改页面。当我单击按钮时,出现了一个错误,显示”NullReferenceException未处理“对象引用未设置为对象的实例”。有什么想法吗???@callum-这是因为变量Month
超出范围。它是在其他方法中定义的。请将其定义为类的字段,而不是方法。