Note that there are some explanatory texts on larger screens.

plurals
  1. POmake WinForms Tooltip show multiple times on one control?
    primarykey
    data
    text
    <p>I'm trying to use the WinForms Tooltip class on a (WinForms) UserControl that is custom drawn (with GDI+). It's legacy code, but I need to maintain it a few more years. I want Tooltips to show up when the cursor is paused at various places. I don't want to do the calculation to know if I should show the tooltip until the cursor has been paused, which lends itself to determining that information in the Popup event. In the non-working sample code below, I expect that I can move the cursor to any corner on the form and see a tool tip. It seems that if I click to remove a tooltip, I don't see one ever after. And the first tool tip to show is not as immediate as I would expect. How do I make this work?</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TestToolTip { public partial class Form1 : Form { private readonly ToolTip _tooltip = new ToolTip(); public Form1() { InitializeComponent(); _tooltip.AutoPopDelay = 10000; _tooltip.InitialDelay = 1000; _tooltip.ReshowDelay = 200; _tooltip.Popup += OnTooltipPopup; _tooltip.SetToolTip(this, "you should never see this"); // we need something or it won't ever trigger Popup } private Point _lp; protected override void OnMouseMove(MouseEventArgs e) { _lp = e.Location; base.OnMouseMove(e); } void OnTooltipPopup(object sender, PopupEventArgs e) { string text = null; if (_lp.X &lt; 100 &amp;&amp; _lp.Y &lt; 100) text = "Top Left"; else if (_lp.X &lt; 100 &amp;&amp; _lp.Y &gt; Height - 100) text = "Bottom Left"; else if (_lp.X &gt; Width - 100 &amp;&amp; _lp.Y &lt; 100) text = "Top Right"; else if (_lp.X &gt; Width - 100 &amp;&amp; _lp.Y &gt; Height - 100) text = "Bottom Right"; var existing = _tooltip.GetToolTip(this); if (existing == text) return; if (text != null) _tooltip.SetToolTip(this, text); // calls into this method e.Cancel = true; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload