How to add tooltip to custom text field on winform

I have a uvSelfLoadingTextBox with multiple instances in a form. I would like to load a tooltip with the _value property at runtime.

I tried

 public ucSelfLoadingTextBox() { Windows.Forms.ToolTip myToolTip; myToolTip.AutomaticDelay = 5000; myToolTip.AutoPopDelay = 50000; myToolTip.InitialDelay = 100; myToolTip.ReshowDelay = 500; myToolTip.SetToolTip(this, _value); 

inside the control, but this does not work.

I tried using a tooltip that is being dragged into the form

  ucSelfLoadingLogicTextBox uc = new ucSelfLoadingLogicTextBox(); toolTipA.SetToolTip(uc,uc._value ); 

and it won’t work.

What is the right way to do this?

+4
source share
2 answers

You forgot to instantiate myToolTip . You need to install it on new Tooltip() .

Also, I don’t think it’s good practice to assign a tooltip in the text box constructor. You can do this in OnCreateControl() (what you need to override).

Thus, your code could become:

 protected override void OnCreateControl() { base.OnCreateControl(); var myToolTip = new System.Windows.Forms.ToolTip { AutomaticDelay = 5000, AutoPopDelay = 50000, InitialDelay = 100, ReshowDelay = 500 }; myToolTip.SetToolTip(this, this.Text); } 
+2
source

Many visible window-shaped controls have the ToolTip property. Just set the tooltip using the one you just created. You can also add a tooltip to your form. Have you tried this?

 myToolTip.ShowAlways = true; 

And try installing this tip on a button control. This may be a good test for your clue.

0
source

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


All Articles