所以这里是基本代码:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
protected Random random;
public Form1()
{
InitializeComponent();
random = new Random();
}
private void Form1_Load(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{
bool button1Clicked = true;
if (button1Clicked == true) { ITIpanel.Visible = true; }
}
private void ITIpanel_Paint(object sender, PaintEventArgs e)
{
ITItimer.Enabled = true;
}
private void ITItimer_Tick(object sender, EventArgs e)
{
double rand = random.NextDouble();
if (rand < .50d) { bluestimPanel.Visible = true; }
else if (rand > .5d) { redstimPanel.Visible = true; }
ITItimer.Enabled = false;
}
private void bluestimPanel_Paint(object sender, PaintEventArgs e)
{
Trialtimer.Enabled = true;
}
private void redstimPanel_Paint(object sender, PaintEventArgs e)
{
Trialtimer.Enabled = true;
}
private void Trialtimer_Tick(object sender, EventArgs e)
{
bluestimPanel.Visible = false;
redstimPanel.Visible = false;
Trialtimer.Enabled = false;
ITIpanel.Visible = true;
}
}
}
如您所见,程序本身相当简单。在 ITItimer 的滴答声中,红色或蓝色面板随机出现。我想修改它,如果 ITItimer 总共滴答 10 次,红色和蓝色面板将分别出现 5 次。
我已经研究了一周左右,还没有找到解决方案。关于如何最好地完成此任务的任何想法?
我实际上得到了以下工作:
double rand = random.NextDouble();
if (rand < .50d && blue < 5) { bluestimPanel.Visible = true; }
else if (blue == 5) { redstimPanel.Visible = true; }
if (rand > .5d && red < 5) { redstimPanel.Visible = true; }
else if (red == 5) { bluestimPanel.Visible = true; }
if (red >= 5 && blue >= 5) { panel1.Visible = true; }
这并不是世界上最漂亮的东西。但它可以完成工作。