The Yellow Blob that codes
The Yellow Blob that codes
CC#
Created by The Yellow Blob that codes on 4/15/2024 in #help
C# Custom Screensaver capturing desktop returns solid color
I am working on creating a screen saver in c# dotnet 8.0. I'm currently trying to do something similar to how the bubbles screen saver screenshots your desktop and uses that as a background. Everything works fine, preview mode works, and running the screensaver as an exe works too. The issue occurs when the screen saver actually runs after idling. Windows shows a solid color before running the screensaver so screenshotting just gives that. Program class
c#
static void ShowScreenSaver()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

foreach (Screen screen in Screen.AllScreens)
{
ScreenSaverForm screensaver = new(screen);
screensaver.Show();
screensaver.Refresh();
}
}
c#
static void ShowScreenSaver()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

foreach (Screen screen in Screen.AllScreens)
{
ScreenSaverForm screensaver = new(screen);
screensaver.Show();
screensaver.Refresh();
}
}
ScreenSaverForm class
c#
public Bitmap screenBitmap;
public ScreenSaverForm(Screen screen)
{
screenBitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format24bppRgb);

Graphics captureGraphics = Graphics.FromImage(screenBitmap);

captureGraphics.CopyFromScreen(screen.Bounds.Location, Point.Empty, screen.Bounds.Size);
captureGraphics.Dispose();

InitializeComponent();
StartPosition = FormStartPosition.Manual;
Bounds = screen.Bounds;

timer1.Start();

DoubleBuffered = true;

Paint += ScreenSaverForm_Paint;
}
c#
public Bitmap screenBitmap;
public ScreenSaverForm(Screen screen)
{
screenBitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format24bppRgb);

Graphics captureGraphics = Graphics.FromImage(screenBitmap);

captureGraphics.CopyFromScreen(screen.Bounds.Location, Point.Empty, screen.Bounds.Size);
captureGraphics.Dispose();

InitializeComponent();
StartPosition = FormStartPosition.Manual;
Bounds = screen.Bounds;

timer1.Start();

DoubleBuffered = true;

Paint += ScreenSaverForm_Paint;
}
I tried a tranparent window but the solid color just appears under it. If anyone has any insight as to how the bubbles screensaver accomplishes it or any other alternative way to screenshot under the solid color that would be appreciated!
8 replies