以下に示すタイマーイベントがあり、この投稿からいくつかの提案を得ました。これのどこが悪いのか教えていただけますか?次のクラッシュが発生しています。
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();
}
}