private static void RunScreenSaver() { var random = new Random(); var viewports = Settings.Default.SpanScreens ? new List<Rectangle> { Screen.AllScreens.Select(s => s.Bounds).Aggregate(Rectangle.Union) } : Screen.AllScreens.Select(s => s.Bounds); foreach (var view in viewports) { var screenSaverForm = new ScreenSaverForm { Bounds = view, TopMost = true, Opacity = Settings.Default.RandomOpacity ? (random.NextDouble() * 0.75D) + 0.25D : Settings.Default.OpacityPercent / 100D }; screenSaverForm.KeyDown += (sender, e) => ShutDownScreenSaver(); screenSaverForm.MouseDown += (sender, e) => ShutDownScreenSaver(); screenSaverForm.MouseMove += (sender, e) => { // Don't end the screen saver if the mouse only moved a tiny bit if (mousePosition != Point.Empty && (e.X - mousePosition.X > 5 || e.X - mousePosition.X < -5 || e.Y - mousePosition.Y > 5 || e.Y - mousePosition.Y < -5)) ShutDownScreenSaver(); else mousePosition = e.Location; }; screenSaverForm.Show(); } Cursor.Hide(); Application.Run(); }
private static void RunPreview(string parent) { long parentHandle; if (!long.TryParse(parent, out parentHandle)) return; var previewForm = new ScreenSaverForm(); if (!NativeMethods.TrySetFormChildWindowStyle(previewForm)) return; if (!NativeMethods.TrySetFormBoundsToMatchParent(previewForm, (IntPtr)parentHandle)) return; NativeMethods.USER32.SetParent(previewForm.Handle, (IntPtr)parentHandle); Application.Run(previewForm); }
private static void RunPreview(string parent) { long parentHandle; if (!long.TryParse(parent, out parentHandle)) { return; } var previewForm = new ScreenSaverForm(); if (!NativeMethods.TrySetFormChildWindowStyle(previewForm)) { return; } if (!NativeMethods.TrySetFormBoundsToMatchParent(previewForm, (IntPtr)parentHandle)) { return; } NativeMethods.USER32.SetParent(previewForm.Handle, (IntPtr)parentHandle); Application.Run(previewForm); }
private static void RunScreenSaver() { var random = new Random(); var viewports = Settings.Default.SpanScreens ? new List <Rectangle> { Screen.AllScreens.Select(s => s.Bounds).Aggregate(Rectangle.Union) } : Screen.AllScreens.Select(s => s.Bounds); foreach (var view in viewports) { var screenSaverForm = new ScreenSaverForm { Bounds = view, TopMost = true, Opacity = Settings.Default.RandomOpacity ? (random.NextDouble() * 0.75D) + 0.25D : Settings.Default.OpacityPercent / 100D }; screenSaverForm.KeyDown += (sender, e) => ShutDownScreenSaver(); screenSaverForm.MouseDown += (sender, e) => ShutDownScreenSaver(); screenSaverForm.MouseMove += (sender, e) => { // Don't end the screen saver if the mouse only moved a tiny bit if (mousePosition != Point.Empty && (e.X - mousePosition.X > 5 || e.X - mousePosition.X < -5 || e.Y - mousePosition.Y > 5 || e.Y - mousePosition.Y < -5)) { ShutDownScreenSaver(); } else { mousePosition = e.Location; } }; screenSaverForm.Show(); } Cursor.Hide(); Application.Run(); }