Taking a screenshot using c# with out including task bar.

前端 未结 1 625
野性不改
野性不改 2021-01-24 05:40

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

相关标签:
1条回答
  • 2021-01-24 06:07

    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.

    0 讨论(0)
提交回复
热议问题