这是我的代码:
public partial class Form1 : Form
{
Graphics g;
bool mouseUP = false;
double dimensions = 4.0;
SolidBrush brush;
public Form1()
{
InitializeComponent();
g = this.CreateGraphics();
brush = new SolidBrush(Color.Black);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mouseUP = false;
backgroundWorker1.RunWorkerAsync(e);
}
private bool mouseIsUP()
{
return mouseUP;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
mouseUP = true;
MessageBox.Show("UP");
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
backgroundWorker1.ReportProgress(0,e.Argument);
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
while (!mouseIsUP())
{
g.FillEllipse(brush, ((MouseEventArgs)e.UserState).X - (int)dimensions / 2, ((MouseEventArgs)e.UserState).Y - (int)dimensions / 2, (int)dimensions, (int)dimensions);
dimensions += 0.2;
Thread.Sleep(10);
}
}
}
为什么永远不会发生 mouseUP 事件???如果我删除 while 我可以看到 MessageBox “UP”...
我试图在按下鼠标时使椭圆变大。当我释放鼠标按钮时,椭圆不应该增长更多。
提前致谢!