0
需要更改動畫激活事件。當用戶雙擊form1
時,該動畫被激活。我需要通過雙擊組件webBrowser1
並觸發button1
觸發動畫。更改動畫激活事件
public partial class Form1 : Form
{
Timer tmr;
public Form1()
{
InitializeComponent();
this.MouseDoubleClick += Form1_MouseDoubleClick;
this.Paint += Form1_Paint;
tmr = new Timer();
tmr.Interval = 10;
tmr.Tick += tmr_Tick;
}
int x;
int step = 5;
void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
tmr.Stop();
x = 0;
tmr.Start();
}
void tmr_Tick(object sender, EventArgs e)
{
x += step;
if (x > this.Width)
{
x = 0;
(sender as Timer).Stop();
}
this.Invalidate();
}
void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red, 0, 0, x, 4);
}
}