Nicke Manarin
Nicke Manarin

Reputation: 3360

Show Tooltip at specific control position via code

I have a textBox that should display a tooltip with a explanation when the user types something wrong.

But i'm not able to put the tooltip in the correct position.

My text Box is inside a groupBox and a TabControl. I tried this:

Point locationOnForm = new Point(this.Left + tabCon.Left + gbDocs.Left + tbKey.Left, this.Top + tabCon.Top + gbDocs.Top + tbKey.Top);

tooltipError.Show("Test", this, locationOnForm , 3000);

But the position is always nearby, never in the right spot.

Upvotes: 0

Views: 2727

Answers (2)

T.S.
T.S.

Reputation: 19394

This will position your tool tip on the right of your text box

tooltipError.Show("TT Text", myGroupBox, textBox1.Left + textBox1.Width + 5, textBox1.Top, 3000);

Notice - you need to set your GroupBox as window - your tool tip must be displayed in the same coordinates as text box. Works well.

On this note, why not use ErrorProvider, which specifically designed for this?

Upvotes: 1

DonBoitnott
DonBoitnott

Reputation: 11035

You can get absolute positioning quite easily. This example puts the ToolTip at the bottom-right corner of the TextBox.

Point pt = new Point(0, 0);
pt.Offset(textBox1.Width - 1, textBox1.Height - 1);
toolTipError.Show("Test", textBox1, pt, 3000);

Remember that the Point you provide to tooltip is relative to the Control you provide, in this case textBox1.

Upvotes: 2

Related Questions