【发布时间】:2013-05-24 09:42:03
【问题描述】:
我有一个计时器事件,如下所示,我从this 帖子中得到了一些建议。你能告诉我这有什么问题吗?我遇到以下崩溃:
无法将 System.Windows.Forms.Timer 类型的对象转换为 System.Windows.Forms.Button 类型。
关于我哪里出错的任何建议??
public MainForm()
{
InitializeComponent();
ButtonTimer.Tick += new EventHandler(ButtonTimer_Tick);
ButtonTimer.Interval = 100;
}
private void ButtonTimer_Tick(object sender, EventArgs e)
{
Button CurrentButton = (Button)sender;
string PressedButton = CurrentButton.Name;
switch (PressedButton)
{
case "BoomUp":break;
}
}
private void BoomUp_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//ButtonTimer.Enabled = true;
ButtonTimer.Start();
}
}
private void BoomUp_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ButtonTimer.Stop();
}
}
【问题讨论】: