
试图把 XP Common Controls 用到实际项目中时,发现气泡提示控件并不象想象中的那样工作。对于textbox来说还是可以正常工作的,但对于象combox box 、lable等控件就好象罢工了一样,为了达到能和 textbox 同样的气泡提示效果,自己补充了一点代码。
namespace HBus.Common
...{
/**//// <summary>
/// 气泡提示控件
/// </summary>
public class xpBalloonTipExtender:Steepvalley.Windows.Forms.APIEnhanced.XPBalloonTip,IDisposable
...{
private System.Windows.Forms.TextBox txt = new System.Windows.Forms.TextBox();
private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
private System.Windows.Forms.Control target = null;
public xpBalloonTipExtender(System.Windows.Forms.Control parent)
: base()
...{
parent.Controls.Add(txt);
txt.Visible = false;
timer.Enabled = false;
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
...{
txt.Visible = false;
timer.Enabled = false;
if (target != null)
...{
target.Focus();
}
target = null;
}
private void Attach(System.Windows.Forms.Control ctrl)
...{
txt.Width = 1;
txt.BorderStyle = System.Windows.Forms.BorderStyle.None;
txt.BackColor = ctrl.BackColor;
txt.Location = ctrl.Location;
txt.Height = ctrl.Height;
txt.Visible = true;
target = ctrl;
}
private void Attach(System.Windows.Forms.Control ctrl, int timeout)
...{
Attach(ctrl);
timer.Interval = 1000 * timeout;
timer.Enabled = true;
}
public new void Hide(System.Windows.Forms.Control ctrl)
...{
if(this.target == ctrl)
...{
base.Hide(txt);
txt.Visible = false;
if (target != null)
...{ target.Focus();
}
target = null;
}
}