You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C# Tooltip设置问题:窗体加载后不显示且无法随按钮切换

Fixing Your Tooltip Issues in WinForms

Hey there, let's work through your Tooltip problems one by one—both the missing Tooltips on form load and the inability to change Tooltips per button.

First: Why Tooltips Aren't Showing On Form Load

Let's start with the basics, since that's often the root cause:

  • Check if your Tooltip is active: The most common gotcha is forgetting to set the Active property to true. If this is false, no Tooltip will ever show, no matter how many times you call SetToolTip. Add this line at the start of your load event:
    toolTip.Active = true;
    
  • Verify your buttons are visible/enabled: Tooltips won't appear on controls that are Visible = false or Enabled = false. Double-check that your buttons aren't hidden or disabled when the form finishes loading.
  • Watch out for the TabControl clear: You're calling tabView.TabPages.Clear(); right at the start. If your buttons are located inside one of those cleared TabPages, they'll be removed from the form entirely—so the Tooltip has no control to attach to. If you need to keep those buttons, move them to another container (like the form itself) before clearing the TabPages:
    // Move buttons to the form before clearing TabPages
    btnACust.Parent = this;
    btnRCust.Parent = this;
    // ... do this for all your buttons
    tabView.TabPages.Clear();
    

Second: Making Tooltips Change With Button State

If you want Tooltips to update when a button's state changes (like disabled vs enabled) or switch correctly when hovering different buttons, here's what to do:

For Dynamic Tooltip Text (e.g., Disabled State)

When a button's state changes, you need to re-call SetToolTip with the new text. For example, add an EnabledChanged event handler to your btnACust:

private void btnACust_EnabledChanged(object sender, EventArgs e)
{
    var button = sender as Button;
    if (button != null)
    {
        toolTip.SetToolTip(button, button.Enabled ? "Add customer" : "Add customer (disabled)");
    }
}

Repeat this pattern for any buttons that need dynamic Tooltip text.

For Smooth Tooltip Switching Between Buttons

If Tooltips aren't switching when you move your mouse from one button to another, adjust the Tooltip's delay properties to make it more responsive:

toolTip.AutoPopDelay = 5000; // Tooltip stays visible for 5 seconds
toolTip.InitialDelay = 200; // Wait 200ms before showing Tooltip
toolTip.ReshowDelay = 100; // Only wait 100ms to show Tooltip on next control

These settings prevent the Tooltip from "sticking" too long, making it switch faster when you hover different buttons.

Full Corrected Load Event Example

Here's how your load event might look with all fixes applied:

private void FrmMain_Load(object sender, EventArgs e)
{
    // Ensure Tooltip is active
    toolTip.Active = true;
    
    // Optimize Tooltip delay settings
    toolTip.AutoPopDelay = 5000;
    toolTip.InitialDelay = 200;
    toolTip.ReshowDelay = 100;

    // Move buttons to form if they were in TabPages (if needed)
    btnACust.Parent = this;
    btnRCust.Parent = this;
    btnSrch.Parent = this;
    btnRef.Parent = this;
    btnEdit.Parent = this;

    tabView.TabPages.Clear();

    // Set initial Tooltip text for all buttons
    toolTip.SetToolTip(btnACust, "Add customer");
    toolTip.SetToolTip(btnRCust, "Remove customer");
    toolTip.SetToolTip(btnSrch, "Search for an item");
    toolTip.SetToolTip(btnRef, "Refresh search criteria and data");
    toolTip.SetToolTip(btnEdit, "Edit selected item");
    // Add any remaining buttons here...
}

Give these steps a try—most Tooltip issues in WinForms boil down to one of these simple fixes.

内容的提问来源于stack exchange,提问作者Jepher

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:36:24