views:

76

answers:

2

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;
    }
}
+1  A: 

Works for me!

Using .NET 3.5 on Windows Vista.

Mark Byers
Thanks for trying! Maybe it's an XP bug that Microsoft fixed in later versions of Windows.
Daniel Stutzbach
It works fine on the Windows 7 machine I have access to, as well. Must be an XP problem.
Daniel Stutzbach
+2  A: 

XP is known for having z-order tooltip bugs. When you used SetWindowPos() on the tooltip, did you mark it as always on top with HWND_TOPMOST?

Anders
Yes, I tried setting HWND_TOPMOST, but it didn't help. The links you gave me have given me some other ideas to try. I'll let you know if any of them pan out.
Daniel Stutzbach