public ScreenSaverForm(int scrn, DonePaintingDelegate donePaintingDelegate, ShutDownDelegate shutDownDelegate) { InitializeComponent(); screenNumber = scrn; Bounds = Screen.AllScreens[screenNumber].Bounds; this.donePaintingDelegate = donePaintingDelegate; this.shutDownDelegate = shutDownDelegate; gameOfLife = new GameOfLife(32); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // Name explains it. SetStyle(ControlStyles.Opaque, true); // Background is taken care of by DrawImage. SetStyle(ControlStyles.UserPaint, true); // if Allpainting is on, so must this. SetStyle(ControlStyles.DoubleBuffer, true); UpdateStyles(); }
public void RunTillShutdown() { donePaintingDel = new DonePaintingDelegate(DonePainting); shutDownDel = new ShutDownDelegate(ShutDown); screenCount = Screen.AllScreens.Length; sf = new ScreenSaverForm[screenCount]; int i = 0; for (i = 0; i < screenCount; i++) { sf[i] = new ScreenSaverForm(i, donePaintingDel, shutDownDel); sf[i].Show(); sf[i].Draw(); } while (screenCount > 0) { WaitHandle.WaitAny(manualEvents, new TimeSpan(0, 0, 0, 2), false); if (shuttingDown == true) { CloseAllScreens(); continue; } try { for (i = 0; i < Screen.AllScreens.Length; i++) { switch (sf[i].PaintStatus) { case PaintStates.ShuttingDown: continue; case PaintStates.PaintError: IfPaintDoneResetStatuses(i); Application.DoEvents(); sf[i].Draw(); break; case PaintStates.OtherPaint: IfPaintDoneResetStatuses(i); break; case PaintStates.NoActivity: case PaintStates.OurPaintPending: case PaintStates.PaintInProgress: break; case PaintStates.PaintSuccessful: IfPaintDoneResetStatuses(i); Application.DoEvents(); sf[i].Draw(); break; } } } catch { Cursor.Show(); throw; } } }