如何在C#中使用TabIndex添加工具提示

时间:2019-04-03 03:05:36

标签: c# winforms

我正在尝试使用C#将工具提示添加到软件中。
我的问题是,他们要求我在使用tabIndex时激活它们。

这是我用来用光标显示工具提示的代码;

public partial class Login : Form
{
    public Login()
    {
        InitializeComponent();

        this.tthelp.SetToolTip(this.cbxUser, "Select a user");
        this.tthelp.SetToolTip(this.txtPas, "Enter your password");
        this.tthelp.SetToolTip(this.btnLogin, "Click on the button or  you can enter");
    }
    //(...)
}

1 个答案:

答案 0 :(得分:0)

您可以将其添加到Control的Entry和Leave事件中。

例如,

var controlTooltipDictionary = new Dictionary<Control, string>
{
    [txtUser] = "Select a user",
    [txtPass] = "Enter your password"
};


foreach (var item in controlTooltipDictionary)
{
    item.Key.Enter += (s, ea) =>
    {
      tthelp.Show(item.Value,item.Key);
    };

    item.Key.Leave += (s, ea) =>
    {
      tthelp.Hide(this);
    };
 }
相关问题