关于ToolTip控件在XP系统中问题

在windows XP系统中ToolTip控件存在一个问题,为一个Button控件添加一个提示信息,代码如下:

1             Button btnTest = new Button();
2             btnTest.Text = "ToolTip测试";
3             btnTest.Location = new Point(100, 100);
4             Controls.Add(btnTest);
5             ToolTip tip = new ToolTip();
6             tip.SetToolTip(btnTest, "是否能显示信息");

但是点击“ToolTip测试”按钮后,鼠标移动到按钮上后提示信息不显示了,在Windows7下可以正常显示。

以下是一种处理方式,供参考:

 1         public Form4()
 2         {
 3             InitializeComponent();
 4 
 5             Button btnTest = new Button();
 6             btnTest.Text = "ToolTip测试";
 7             btnTest.Location = new Point(100, 100);
 8             Controls.Add(btnTest);
 9             btnTest.MouseHover += new EventHandler(btnTest_MouseHover);
10             btnTest.MouseLeave += new EventHandler(btnTest_MouseLeave);
11         }
12 
13         private ToolTip tip = new ToolTip();
14 
15         void btnTest_MouseHover(object sender, EventArgs e)
16         {
17             if (tip == null)
18             {
19                 tip = new ToolTip();
20             }
21             tip.SetToolTip(btnTest, "是否能显示信息");
22         }
23 
24         void btnTest_MouseLeave(object sender, EventArgs e)
25         {
26             if (tip != null)
27             {
28                 tip.RemoveAll();
29             }
30         }
原文地址:https://www.cnblogs.com/lgx040605112/p/2848040.html