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



我正在尝试将工具提示添加到具有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");
    }
    //(...)
}

您可以将其添加到 Control 的 Enter 和 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);
    };
 }

最新更新