C# 更改动画激活事件
需要更改动画激活事件。当用户双击C# 更改动画激活事件,c#,.net,winforms,C#,.net,Winforms,需要更改动画激活事件。当用户双击form1时,此动画被激活。我需要通过双击组件webBrowser1和触发按钮1来触发动画 public partial class Form1 : Form { Timer tmr; public Form1() { InitializeComponent(); this.MouseDoubleClick += Form1_MouseDoubleClick; this.Paint += Form1_Paint; tmr = new
form1
时,此动画被激活。我需要通过双击组件webBrowser1
和触发按钮1
来触发动画
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);
}
}
除了处理MouseDoubleClick事件,您还应该监听webBrowser1和button1。大概是这样的:
this.MouseDoubleClick += Form1_MouseDoubleClick;
webBrowser1.MouseDoubleClick += Form1_MouseDoubleClick;
//I dont know the exact method for the button but it should be similar to this:
button1.Click += Form1_MouseDoubleClick;