【发布时间】:2013-10-08 13:08:53
【问题描述】:
我有一个组框设置可见 true。里面有 3 个按钮 .btn1 可见 true.btn 2 ,btn 3 可见 false..想要在确切位置显示这 3 个按钮的工具提示吗?
我现在在做什么
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
private ToolTip toolTip = new ToolTip();
private bool isShown = false;
ToolTip toolTip1 = new ToolTip();
bool IsShown = false;
public Form1()
{
InitializeComponent();
button1.Enabled = false;
toolTip1.InitialDelay = 0;
}
private void Form1_MouseMove_1(object sender, MouseEventArgs e)
{
//if (button1 == this.GetChildAtPoint(e.Location))
//{
// if (!isShown)
// {
// toolTip.Show("MyToolTip", this, e.Location);
// isShown = true;
// }
//}
//else
//{
// toolTip.Hide(textBox1);
// isShown = false;
//}
Control ctrl = this.GetChildAtPoint(e.Location);
if (ctrl != null)
{
if (ctrl == this.button1 && !IsShown)
{
string tipstring = this.toolTip1.GetToolTip(this.button1);
this.toolTip1.Show(tipstring, this.button1, this.button1.Width / 2, this.button1.Height / 2);
IsShown = true;
}
}
else
{
this.toolTip1.Hide(this.button1);
IsShown = false;
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = true;
// Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(this.button1, "My button1");
}
}
}
我尝试了 1 个按钮,但失败了……需要帮助
我什至尝试过
http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.aspx
但它不适用于禁用的控件
【问题讨论】:
-
您希望何时显示工具提示?我会考虑将事件 MouseHover 设置为 tooltip.Show() 并将 MouseLeave 设置为 tooltip.Hide()。但我不确定我是否完全理解您想要实现的目标。
-
我正在尝试显示放置在组框内的禁用控件的工具提示..
-
能否举个例子
标签: c# .net winforms button tooltip