Mousehover tooltip showing multiple times

I have a custom control (C #, visual studio). I want to show a tooltip about a mousehover event.

However, no matter what I do, it either never shows, or has a chance to show several times.

I thought it would be as simple as:

private void MyControl_MouseHover(object sender, EventArgs e)
{
    ToolTip tT = new ToolTip();

    tT.Show("Why So Many Times?", this);
}

But that does not work. I tried a bunch of things, but can't get it to work. I would like the tooltip to be part of the component because I want to access the private fields for display.

Thanks for any help

+3
source share
4 answers

?

public ToolTip tT { get; set; }

public ClassConstructor()
{
    tT = new ToolTip();
}

private void MyControl_MouseHover(object sender, EventArgs e)
{
    tT.Show("Why So Many Times?", this);
}
+7

MouseHover , . , , . . .

+1

, .

Form1.Designer.cs: ( )

partial class Form1
{
    private System.ComponentModel.IContainer components = null;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.ToolTip toolTip1;

    // ...

    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.label1 = new System.Windows.Forms.Label();
        this.toolTip1 = new System.Windows.Forms.Tooltip(this.components);

        // ...

        this.toolTip1.SetToolTip(this.label1, "abc");

        // ...
    }
}

, .

+1

MSDN !

:


private System.Windows.Forms.ToolTip toolTip1;

private void YourControl_MouseHover(object sender, EventArgs e)
{
     toolTip1 = new System.Windows.Forms.ToolTip();
     this.toolTip1.SetToolTip(this.YourControl, "Your text here :) ");
     this.toolTip1.ShowAlways = true;
}

,

0

Source: https://habr.com/ru/post/1721802/


All Articles