我有一个带有组合的表单来接收客户和按钮。 选择客户并将鼠标移到按钮上时,将显示工具提示,其中包含有关此客户的信息。
我使用ToolTip_Draw定制了工具提示。
所有这些都很好。
问题在于,当我更改所选客户,然后将鼠标移到按钮上时,会显示几个工具提示文本。我之前选择的每个客户都有一个。
我试图以某种方式清空de ToolTip,但似乎没有任何效果。
private void bttCitas_MouseHover(object sender, EventArgs e)
{
string mSQL = @" SELECT one, two, three
FROM customers
WHERE id = " + comboCliente.SelectedValue + ";";
DataTable tablaTemp = retrieveData(mSQL);
string customerText = ConvertDataTableToString(tablaTemp);
System.Windows.Forms.ToolTip Emergente = new System.Windows.Forms.ToolTip();
Emergente.OwnerDraw = true;
Emergente.Draw += new DrawToolTipEventHandler(ToolTip_Draw);
Emergente.AutoPopDelay = 150000;
Emergente.InitialDelay = 500;
Emergente.ReshowDelay = 500;
Emergente.SetToolTip(this.bttCitas, customerText);
}
void ToolTip_Draw(object sender, DrawToolTipEventArgs e)
{
using (e.Graphics)
{
Font f = new Font("Courier New", 9.0f);
e.DrawBackground();
e.DrawBorder();
SolidBrush myBrush = new SolidBrush(GLOBALToolTipFontColor);
e.Graphics.DrawString(e.ToolTipText, f, myBrush, new PointF(2, 2));
}
}
答案 0 :(得分:0)
我终于弄明白了会发生什么。
我需要从MouseOver事件中声明Emergente,然后将它放在MouseLeave中:
private ToolTip Emergente;
private void bttCitas_MouseHover(object sender, EventArgs e)
{
string mSQL = @" SELECT one, two, three
FROM customers
WHERE id = " + comboCliente.SelectedValue + ";";
DataTable tablaTemp = retrieveData(mSQL);
string customerText = ConvertDataTableToString(tablaTemp);
Emergente = new System.Windows.Forms.ToolTip();
Emergente.OwnerDraw = true;
Emergente.Draw += new DrawToolTipEventHandler(ToolTip_Draw);
Emergente.AutoPopDelay = 150000;
Emergente.InitialDelay = 500;
Emergente.ReshowDelay = 500;
Emergente.SetToolTip(this.bttCitas, customerText);
}
void ToolTip_Draw(object sender, DrawToolTipEventArgs e)
{
using (e.Graphics)
{
Font f = new Font("Courier New", 9.0f);
e.DrawBackground();
e.DrawBorder();
SolidBrush myBrush = new SolidBrush(GLOBALToolTipFontColor);
e.Graphics.DrawString(e.ToolTipText, f, myBrush, new PointF(2, 2));
}
}
private void bttCitas_MouseLeave(object sender, EventArgs e)
{
Emergente.Dispose();
}