我正在使用一个计时器来记录我在图片框中执行的点击位置达到计时器计时的指定时间。作为下一步,我添加了PictureBox绘制事件,以显示我在pictureBox中点击的小圆圈。它工作得很好但计时器滴答以某种方式变得禁用。接下来我注意到,如果我从FORM InitializeComponent()函数中注释掉以下行,则计时器开始工作:
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
这是来自InitializeComponent()函数的timer1和picturebox1设置:
this.timer1 = new System.Windows.Forms.Timer();
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.pictureBox1.Image = global::Omers_project.Properties.Resources.img_002;
this.pictureBox1.Location = new System.Drawing.Point(282, 158);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(694, 492);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
下面给出Timer1_Click和PictureBox1_Click函数:
private void timer1_Tick(object sender, EventArgs e)
{
passes--;
textBox_time_passed.Text = passes.ToString();
if (passes == 0)
{
timer1.Stop();
MessageBox.Show("Time is up");
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MouseEventArgs eM = (MouseEventArgs)e;
temp_storage.x = eM.X;
temp_storage.y = eM.Y;
myList.Add(temp_storage);
count++;
textBox6.Text = Convert.ToString(count);
}
因此,我一次只能使用其中一个,但无法同时使用这两个功能。请帮我解决这个问题。
答案 0 :(得分:0)
我真的不知道你的代码是什么样的,但我建议执行timer Start()
方法而不是Enable = True
。
另外......你在不同的线程中对PictureBox绘制事件做任何代码吗?
如果仍然无效,请提供更多代码,以便我们更好地了解。
干杯