C# 中单击错误时更新 pictureBox 的计时器
我有以下代码 -
private void button1_Click(object sender, EventArgs e)
{
_soundplayer.Play();
timer1_Tick();
}
private void timer1_Tick()
{
pictureBox1.Image = imageList1.Images[imgIndex++];
}
由于某种原因,这会在 Form1.Designer.cs
中返回错误 -
Error 1 No overload for 'timer1_Tick' matches delegate 'System.EventHandler'
单击 button1 时,pictureBox1 中的图像应随着计时器刻度每 2 秒更改一次,但是我可以无法克服这个错误。请指教。
I have the following code-
private void button1_Click(object sender, EventArgs e)
{
_soundplayer.Play();
timer1_Tick();
}
private void timer1_Tick()
{
pictureBox1.Image = imageList1.Images[imgIndex++];
}
For some reason this brings back the error in the Form1.Designer.cs
-
Error 1 No overload for 'timer1_Tick' matches delegate 'System.EventHandler'
When button1 is clicked the image in pictureBox1 should change every 2 seconds with the timer tick, however I can't get past this error. Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tick 事件是 EventHandler 类型的事件。它需要事件处理程序的两个参数:
这需要您像这样修改 Click 事件处理程序:
使用设计器添加事件处理程序可以让您摆脱这样的麻烦。选择计时器,单击“属性”窗口中的闪电图标,然后双击“勾选”。
The Tick event is an event of type EventHandler. It requires two arguments for the event handler:
Which requires you to modify the Click event handler like this:
Using the designer to add event handlers can keep you out of trouble like this. Select the timer, click the lightning bolt icon in the Properties window and double-click Tick.
当您单击按钮时启动计时器。并将计时器间隔设置为 2000 毫秒。 Timer_tick 事件将每 2 秒自动创建一次。
Start timer, when you clicked on a button. And set timer interval to 2000 milliseconds. Timer_tick event will be created automatically every 2 seconds.