Search code examples
c#drop-down-menuscreenshotmenubar

Take screendump from menu but it stays open thus in the picture


I have a feature in my program where the user can make a screendump of the main form. To do this the user must from the menu select File | Take screendump. This works. However, the dropdown menu remains open and partially visible when the screendump is taken. Some other controls are on top of it though. How can I ensure that the dropdown is closed BEFORE the screenshot is taken?

I have tried to include HideDropDown() on both the menu and the menu item but neither helps. I have even tried to make the entire menu invisible but no luck either.

private void toolStripMenuItem_screenDumpProgram_Click(object sender, EventArgs e)
{
    ... HideDropDown() ... various tests

    Bitmap screendump = new Bitmap(Width, Height);
    Graphics gfx = Graphics.FromImage(screendump);
    gfx.CopyFromScreen(Location, Point.Empty, Size);

    screendump.Save("MyScreenshot.png", ImageFormat.Png);
}

Any ideas how to avoid this issue?


Solution

  • I think what you need is not a screenshot but a rendering of your Form into a Bitmap. This has been done before. Other solutions are available using search.