简体   繁体   English

C#Winform ToolTip启用/禁用

[英]C# Winform ToolTip Enable/Disable

I am trying to give the user an option to disable and enable the tool tips. 我正在尝试为用户提供禁用和启用工具提示的选项。 In my application, I created a menu strip with two options (EnableToolTip/DisableToolTip). 在我的应用程序中,我创建了一个菜单条,其中包含两个选项(EnableToolTip / DisableToolTip)。 Here my code to set the tool Tips (where ttObj is a global object): 这里是我设置工具提示的代码(其中ttObj是全局对象):

private void loadToolTips()
{

    ttObj.AutoPopDelay = 5000;
    ttObj.InitialDelay = 1000;
    ttObj.ReshowDelay = 500;

    ttObj.SetToolTip(this.btnSetRolesType, "A");
    ttObj.SetToolTip(btnCreateUser, "B");
    ttObj.SetToolTip(btnModifyNum, "C");
    ttObj.SetToolTip(btnFindDups, "D");
    ttObj.ShowAlways = false;

}

And this is where I am trying to disable the tooltips 这就是我要禁用工具提示的地方

private void enableToolStripMenuItem_Click(object sender, EventArgs e)
{
    enableToolStripMenuItem.Checked = true;
    disableToolStripMenuItem.Checked = false;
}

private void disableToolStripMenuItem_Click(object sender, EventArgs e)
{
    disableToolStripMenuItem.Checked = true;
    enableToolStripMenuItem.Checked = false;
    ttObj.Hide(this); //this doesn't do anything

}

There isn't much on google or stackoverflow. Google或stackoverflow上没有多少东西。 Some help is much appreciated. 非常感谢您的帮助。

To enable/disable the tool tips, use the Active property. 要启用/禁用工具提示,请使用Active属性。 Set it False to disable and when you set it back to True , you'll have your tool tips again without having to re-add them. 将其设置为False可禁用,然后将其重新设置为True ,则无需重新添加即可再次获得工具提示。

private void enableToolStripMenuItem_Click(object sender, EventArgs e)
{
    enableToolStripMenuItem.Checked = true;
    disableToolStripMenuItem.Checked = false;

    ttObj.Active = true;
}

private void disableToolStripMenuItem_Click(object sender, EventArgs e)
{
    disableToolStripMenuItem.Checked = true;
    enableToolStripMenuItem.Checked = false;

    ttObj.Active = false;
}

Alternatively, to just wipe them out, use RemoveAll() . 另外,要清除它们,请使用RemoveAll() You'll have to re-run loadToolTips() to add them back. 您必须重新运行loadToolTips()才能将其重新添加。

private void disableToolStripMenuItem_Click(object sender, EventArgs e)
{
    disableToolStripMenuItem.Checked = true;
    enableToolStripMenuItem.Checked = false;

    ttObj.RemoveAll();   
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM