我正在使用計時器記錄在計時器計時的指定時間量內在圖片框中執行的點擊位置。作爲下一步,我添加了PictureBox繪畫事件以顯示我在pictureBox中點擊的小圓圈。它完美的工作,但計時器滴答不知何故變得殘疾。接下來,我注意到,如果我註釋掉形式的InitializeComponent()函數下面的線,計時器開始工作:通過Picturebox繪畫事件自動禁用計時器刻度事件
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
這裏是在InitializeComponent()的定時器1和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);
}
因此,我可以在同一時間只能使用其中的一個,但不能同時使用functionaliti es在同一時間。請幫我解決這個問題。
請說明您是如何創建計時器的。 –
您的計時器語句訪問相同的圖片框?如果可以請包括你的圖片盒相關的計時器代碼?或者您嘗試在時間內或Paint事件中委派您訪問圖片框的部分? –
這裏是關於定時器的創建和設置的代碼部分(在InitializeComponent()函數中): this.timer1 = new System.Windows.Forms.Timer(); this.timer1.Interval = 1000; this.timer1.Tick + = new System.EventHandler(this.timer1_Tick); – Mani