【发布时间】:2011-02-13 12:53:16
【问题描述】:
我有一个Opacity 小于 1.0 的表单。我有一个与表单上的标签关联的工具提示。当我将鼠标悬停在标签上时,工具提示显示在 under 表单而不是 over 表单。如果我将不透明度保留为默认值 1.0,则工具提示会正确显示在表单上。但是,我的形式显然不再是半透明的。 ;-)
我尝试使用SetWindowPos() 手动调整工具提示的位置,并使用CreateWindowEx()“手动”创建工具提示,但问题仍然存在。这让我怀疑这是一个 Win32 API 问题,而不是在 Win32 之上运行的 Windows 窗体实现的问题。
为什么工具提示会出现在表单下方,更重要的是,我怎样才能让它出现在表单应该出现的位置?
编辑:这似乎是 XP 独有的问题。 Vista 和 Windows 7 可以正常工作。我仍然想找到一种解决方法,让工具提示出现在 XP 的表单上方。
这是一个演示问题的最小程序:
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 提供了一个最小的示例,即使我自己无法重现它。
-
我猜当你设置不透明度时,本机窗口会获得 WS_EX_LAYERED 样式,这就是为什么只有在不透明度
标签: c# winforms winapi tooltip opacity