Re: Custom ToolTip on ToolStrip

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Linda,

It does work, but there are also some strange behavior happening.
I have a ToolStrip containing a ToolStripTextBox and a ToolStripLabel - very
similar to your sample below.

The ToolStrip contains 3 differently places where the mouse may hover over:
the ToolStrip, the ToolStripTextBox and the ToolStripLabel.

The tooltips do show up and change when moving from the TextBox to the Label
and back.
The funny thing is that the latest shown ToolTipText also appear when stay
over the ToolStrip - which should not happen.

Any explanation for this strange behavior ??

BR
Peter


"Linda Liu [MSFT]" <v-lliu@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:AEqJmqfCHHA.5964@xxxxxxxxxxxxxxxxxxxxxxxx
Hi Peter,

Based on my understanding, you'd like to use your own ToolTip component to
display tooltip on a ToolStrip control. If I have any misunderstanding,
please feel free to correct me.

I am sorry that I don't think we have a chance to replace the default
ToolTip component associated to a ToolStrip control with a custom ToolTip
component, because ToolStrip class doesn't expose a property for the
default ToolTip it uses.

But I think we could accomplish what you want by other means.

Firstly, set the ShowItemToolTips property of the ToolStrip control to
false.

Secondly, add two methods in your form's code to show and hide tooltip
using the custom ToolTip component. The following is a sample. It assumes
that the ToolStrip's name is toolStrip1, which contains two items called
toolStripButton1 and toolStripButton2 and that the custom ToolTip's name
is
toolTip1.

private void toolStripItem_MouseHover(object sender, EventArgs e)
{
ToolStripItem item = sender as ToolStripItem;

switch (item.Name)
{
case "toolStripButton1":
this.toolTip1.Show(this.toolStripButton1.ToolTipText,
this.toolStrip1, this.toolStripButton1.Bounds.Left +
this.toolStripButton1.Bounds.Width/2,
this.toolStripButton1.Bounds.Height);
break;
case "toolStripButton2":
this.toolTip1.Show(this.toolStripButton2.ToolTipText,
this.toolStrip1,
this.toolStripButton2.Bounds.Left+this.toolStripButton2.Bounds.Width/2,
this.toolStripButton2.Bounds.Height);
break;
}
}

private void toolStripItem_MouseLeave(object sender, EventArgs e)
{
this.toolTip1.Hide(this.toolStrip1);
}

Thirdly, associate the method "toolStripItem_MouseHover" with the
MouseHover event of each item in the ToolStrip control. Associated the
method "toolStripItem_MouseLeave" with the MouseLeave event of each item
in
the ToolStrip control.

Build the project and run it. When you rest the pointer on the ToolStrip,
you should see your custom ToolTip shows tooltip.

Please try my suggestion and tell me the result.
If my suggestion is not appropriate to your scenario, please feel free to
let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support



.


Quantcast