On XP, how do I get the tooltip to appear above a transclucent form?

Posted by Daniel Stutzbach on Stack Overflow See other posts from Stack Overflow or by Daniel Stutzbach
Published on 2010-04-28T20:09:25Z Indexed on 2010/04/28 21:07 UTC
Read the original article Hit count: 228

Filed under:
|
|
|
|

I have an form with an Opacity less then 1.0. I have a tooltip associated with a label on the form. When I hover the mouse over the label, the tooltip shows up under the form instead of over the form. If I leave the Opacity at its default value of 1.0, the tooltip correctly appears over the form. However, my form is obviously no longer translucent. ;-)

I have tried manually adjusting the position of the ToolTip with SetWindowPos() and creating a ToolTip "by hand" using CreateWindowEx(), but the problem remains. This makes me suspect its a Win32 API problem, not a problem with the Windows Forms implementation that runs on top of Win32.

Why does the tooltip appear under the form, and, more importantly, how can I get it to appear over the form where it should?

Edit: this appears to be an XP-only problem. Vista and Windows 7 work correctly. I'd still like to find a workaround to get the tooltip to appear above the form on XP.

Here is a minimal program to demonstrate the problem:

using System;
using System.Windows.Forms;

public class Form1 : Form
{
    private ToolTip toolTip1;
    private Label label1;

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    public Form1()
    {
        toolTip1 = new ToolTip();
        label1 = new Label();
        label1.Location = new System.Drawing.Point(105, 127);
        label1.Text = "Hover over me";
        label1.AutoSize = true;
        toolTip1.SetToolTip(label1, "This is a moderately long string, "
               + "designed to be very long so that it will also be quite long.");
        ClientSize = new System.Drawing.Size(292, 268);
        Controls.Add(label1);
        Opacity = 0.8;
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms