4

I have a uvSelfLoadingTextBox with multiple instances on a form. I would like to load the tooltip with the _value property at run time.

I've 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 that does not work.

I have tried using the tooltip that is dragged onto the form

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

and that does not work.

What is the correct way to do this?

1
  • 2
    Are you getting some kind of exception? Commented May 9, 2012 at 19:18

2 Answers 2

2

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

Also, I don't think it's a good practice to assign the tooltip in the textbox's constructor. You could do this in OnCreateControl() (that you need to override).

Your code could therefore 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);
}
Sign up to request clarification or add additional context in comments.

3 Comments

oops this works ok for this.Text at design time but it only shows the old value of the control e.g. text = designtime and the text value is changed by code to text = newvalue the tooltip still shows "designtime".
Is there a way to make the control refresh do i need a onChange event of some sort?
protected override void OnTextChanged(EventArgs e) Thanks wOlf got it working perfectly now thanks to your help.
0

Many visible controls on windows form have ToolTip property. Just set the Tooltip with your newly created one. You can also add tooltip to your form. Have you tried this?

myToolTip.ShowAlways = true;

And try to set this tip to a button control. This may be a good test for your tooltip.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.