private void button2_Click(object sender, EventArgs e) { Point cursorPoint = Cursor.Position; Stopwatch sw = Stopwatch.StartNew(); try { IntPtr handle = FormHelper.FindWindow(null, "扫雷"); if (handle.ToInt32() > 0) { if (sweepzone == null) { sweepzone = new SweepZone(handle); } sweepzone.Refresh(); sweepzone.Recognize(); ShowMineImage(); picZone.Image = sweepzone.PredictImage(); //picZone.Image = sweepzone.ZoneImage; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sw.Stop(); Cursor.Position = cursorPoint; } }
private void button4_Click(object sender, EventArgs e) { ThreadStarter.Start(() => { Point cursorPoint = Cursor.Position; Stopwatch sw = Stopwatch.StartNew(); try { if (sweepzone == null) { IntPtr handle = FormHelper.FindWindow(null, "扫雷"); if (handle.ToInt32() > 0) { sweepzone = new SweepZone(handle); sweepzone.Refresh(); sweepzone.Recognize(); ShowMineImage(); picZone.Image = sweepzone.PredictImage(); } } while (true) { if (sw.ElapsedMilliseconds > 60000) { break; } if (!sweepzone.Sweep()) { break; } sweepzone.Refresh(); sweepzone.Recognize(); this.InvokeMethod(() => { picZone.Image = sweepzone.PredictImage(); }); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { //Cursor.Position = cursorPoint; sw.Stop(); } }); }