Вопрос

How to take screenshot using c# with out including task bar.I tried some codes but it takes whole screen.

Это было полезно?

Решение

try with Screen.PrimaryScreen.WorkingArea it gives you the screen excluding task bar

Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width,
                           Screen.PrimaryScreen.WorkingArea.Height,
                           PixelFormat.Format32bppArgb);

Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);


gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.WorkingArea.X,
                            Screen.PrimaryScreen.WorkingArea.Y,
                            0,
                            0,
                            Screen.PrimaryScreen.WorkingArea.Size,
                            CopyPixelOperation.SourceCopy);

bmpScreenshot.Save("Screenshot.png", ImageFormat.Png);

Screen.WorkingArea Property

Gets the working area of the display. The working area is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top