2

I am making a screenshotting application using C# and WinForms and so I need my form to hide itself so it can take a picture of the screen. This I have accomplished, but if I hover over the New Screenshot button before taking the screenshot and the tooltip pops up, the tooltip doesn't get hidden with the form and ends up being in the screenshot.

I've tried setting the AutoToolTip property to false and setting the tooltip text to null, but it makes no difference.

One thing that did work was calling main_toolStrip.Dispose();, but then of course it disappears from the form after the form unhides itself.

I've got this code so far:

private void newScreenshot_btn_Click(object sender, EventArgs e)
    {
        main_toolStrip.ShowItemToolTips = false;
        this.WindowState = FormWindowState.Minimized;
        this.Visible = false;
        this.ShowInTaskbar = false;
        System.Threading.Thread.Sleep(2000);
        //screenshot code is here
        main_toolStrip.ShowItemToolTips = true;
        this.ShowInTaskbar = true;
        this.Visible = true;
        this.Size = new Size(1000, 800);
        this.WindowState = FormWindowState.Normal;
        prepareMenus(); //enables the required buttons on the toolstrip
    }

As you can see by the code, ShowItemToolTips hasn't helped either.

I don't particularly want to remove the tooltip from the button, however.

Images:

This is a screenshot of a screenshot taken by my program demonstrating the tooltip problem:

enter image description here

And the toolbar button that creates the tooltip:

enter image description here

Also note that this isn't an explicitly created ToolTip control; it is the one "included", if you like, with the ToolStrip control.

Dog Lover
  • 618
  • 1
  • 6
  • 18
  • Just to try to pinpoint the problem. Replace the Sleep with Application.DoEvents. – Steve Dec 02 '16 at 09:19
  • @Steve Unfortunately no change. Also, the `Sleep` isn't actually there to combat the problem; it's there to give the user time to say focus the window they want to screenshot. – Dog Lover Dec 02 '16 at 09:21
  • OK, but I was thinking about the fact that your code doesn't seem to give the form engine the pause to close everything. – Steve Dec 02 '16 at 09:22
  • @Steve I've just tried `Application.DoEvents();` before the `Sleep` code, and interestingly the tooltip fades a bit. It doesn't disappear completely until after the screenshot though. – Dog Lover Dec 02 '16 at 09:25
  • Well I hesitate to say that but try two times then. In any case Application.DoEvents is considered very dangerous for the stability of your code. [Read the answers in this question](http://stackoverflow.com/questions/5181777/use-of-application-doevents). In particular the one from Mr Hans Passant – Steve Dec 02 '16 at 09:30
  • I don't suppose anyone would be kind enough to start a bounty on this question? It seems to be the only one of its sort, and I still haven't found a solution. I don't have a comfortable level of rep to offer :( – Dog Lover Dec 15 '16 at 05:17

1 Answers1

0

I have encountered the same issue and have not found a solution better than disabling animations and fading that cause tooltip to remain and using Application.DoEvents(). In some cases it worked for me without using Application.DoEvents(). The animations and fading can be safely reenabled immediately after.

Code example:

        toolTipMain.UseAnimation = false;
        toolTipMain.UseFading = false;
        toolTipMain.Hide(this);
        Application.DoEvents();
        toolTipMain.UseAnimation = true;
        toolTipMain.UseFading = true;
Murumuru
  • 33
  • 6