正在发生的事情是,即使questionNr设置为1,它也不会改变ans1-4的.Text属性以及questionLabel。任何帮助,将不胜感激。另外作为一个子问题,是否可以按照if(ans1.Clicked = true)的方式做一些事情?
public partial class Form1 : Form
{
int pointCounter = 0;
private SoundPlayer _soundPlayer;
int questionNr = 1;
public Form1()
{
InitializeComponent();
_soundPlayer = new SoundPlayer("song.wav");
}
private void pictureBox1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.amazon.com/Chuck-Seasons-One-Five-Blu-ray/dp/B007AFS0N2");
}
private void Form1_Load(object sender, EventArgs e)
{
_soundPlayer.PlayLooping();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void muteButton_Click(object sender, EventArgs e)
{
if (muteButton.Text == "Mute")
{
muteButton.Text = "Unmute";
_soundPlayer.Stop();
}
else
{
muteButton.Text = "Mute";
_soundPlayer.PlayLooping();
}
}
private void playButton_Click(object sender, EventArgs e)
{
ans1.Visible = true;
ans2.Visible = true;
ans3.Visible = true;
ans4.Visible = true;
playButton.Visible = false;
}
public void question()
{
if (questionNr == 1)
{
questionLabel.Text = "What is Chuck's full name?";
ans1.Text = "Charles Irving Bartowski";
ans2.Text = "Charles Richard Bartowski";
ans3.Text = "Charles Luke Bartowski";
ans4.Text = "Zachary Strahovski";
}
}
private void ans1_Click(object sender, EventArgs e)
{
}
private void ans2_Click(object sender, EventArgs e)
{
}
private void ans3_Click(object sender, EventArgs e)
{
}
private void ans4_Click(object sender, EventArgs e)
{
}
}
}
答案 0 :(得分:0)
调用question()
方法的表单。首先从您需要的地方调用该方法。
例如:FormLoad / Button click等。然后尝试
public Form1()
{
InitializeComponent();
_soundPlayer = new SoundPlayer("song.wav");
question();
}
如果你在Form Load事件中设置一个断点并查看你的代码是如何执行的,那就太好了。然后你就可以了解代码的流程。