Can One Not Set a ToolTip for a ToolStripProgressBar?

  • Thread starter Thread starter JonOfAllTrades
  • Start date Start date
J

JonOfAllTrades

Good afternoon. As ToolStripProgressBar does not inherit from Control, it
doesn't seem possible to use a ToolTip's SetToolTip feature. Yet it does
have a ToolTipText property. Am I missing something?
Thanks!
 
JonOfAllTrades said:
Good afternoon. As ToolStripProgressBar does not inherit from Control, it
doesn't seem possible to use a ToolTip's SetToolTip feature. Yet it does
have a ToolTipText property. Am I missing something?
Thanks!

Hi Jon,

The ToolStripProgressBar inherits from ToolStripItem which has its own
implementation of ToolTip. You may notice that ToolTipText does not appear
as a property in the designer on regular controls until you add a ToolTip
control. All ToolStripItems have this property permanently.
 
Morten Wennevik said:
Hi Jon,

The ToolStripProgressBar inherits from ToolStripItem which has its own
implementation of ToolTip. You may notice that ToolTipText does not appear
as a property in the designer on regular controls until you add a ToolTip
control. All ToolStripItems have this property permanently.

I had noticed that, but how do I use it? Setting the ToolTipText property
has had no effect, I do not get any tip. I can set a normal tool tip for the
strip:

ToolTip.SetToolTip(StatusStrip, newToolTip);

But this has no effect:

ProgressQueue.ToolTipText = newToolTip;

If I use the former method, I get a tip but for the whole strip, but *not*
the progress meter. If I use the latter method, I get nothing at all.
 
I had noticed that, but how do I use it? Setting the ToolTipText property
has had no effect, I do not get any tip. I can set a normal tool tip for the
strip:

ToolTip.SetToolTip(StatusStrip, newToolTip);

But this has no effect:

ProgressQueue.ToolTipText = newToolTip;

If I use the former method, I get a tip but for the whole strip, but *not*
the progress meter. If I use the latter method, I get nothing at all.

ProgressQueue.ToolTipText = "Hello World"
 
Jack Jackson said:
ProgressQueue.ToolTipText = "Hello World"

Perhaps I should have been more specific. "newToolTip" in my previous
example is a string, with a value in the format of "There are X items in the
queue, current state is Y." I do understand how to assign to a property, and
yes I've verified that the string has the expected value and is neither null
nor empty.
 
JonOfAllTrades said:
Perhaps I should have been more specific. "newToolTip" in my previous
example is a string, with a value in the format of "There are X items in the
queue, current state is Y." I do understand how to assign to a property, and
yes I've verified that the string has the expected value and is neither null
nor empty.

Hi Jon,

That is basically all you have to do. Once you set ToolTipText the
toolstripcontrol should display the tooltip. The code sample below should
display the current value whenever you move your mouse over the progressbar.

BackgroundWorker bw = new BackgroundWorker();
public Form1()
{
InitializeComponent();

bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.WorkerReportsProgress = true;
}

void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
toolStripProgressBar1.Value = 0;
}

void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
toolStripProgressBar1.Value = e.ProgressPercentage;
toolStripProgressBar1.ToolTipText =
"There are " + toolStripProgressBar1.Value + " out of "
+ toolStripProgressBar1.Maximum + " processed files";
}

void bw_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(100);
bw.ReportProgress(i);
}
}

protected override void OnLoad(EventArgs e)
{
bw.RunWorkerAsync();
}
 
Morten Wennevik said:
That is basically all you have to do. Once you set ToolTipText the
toolstripcontrol should display the tooltip. The code sample below should
display the current value whenever you move your mouse over the progressbar.

BackgroundWorker bw = new BackgroundWorker();
public Form1()
{
InitializeComponent();

bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.WorkerReportsProgress = true;
}

void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
toolStripProgressBar1.Value = 0;
}

void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
toolStripProgressBar1.Value = e.ProgressPercentage;
toolStripProgressBar1.ToolTipText =
"There are " + toolStripProgressBar1.Value + " out of "
+ toolStripProgressBar1.Maximum + " processed files";
}

void bw_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(100);
bw.ReportProgress(i);
}
}

protected override void OnLoad(EventArgs e)
{
bw.RunWorkerAsync();
}

Groovy. But it's not working; why might that be? I have a ToolTip object
on my Form, could that be interfering?
No: it turns out that StatusStrip has a ShowItemToolTips property, which is
False by default. Changing this fixes the problem.
 
JonOfAllTrades said:
Groovy. But it's not working; why might that be? I have a ToolTip object
on my Form, could that be interfering?
No: it turns out that StatusStrip has a ShowItemToolTips property, which is
False by default. Changing this fixes the problem.

Ah, I should have thought of that one. However, the default is True ... ;)
 
Morten Wennevik said:
Ah, I should have thought of that one. However, the default is True ... ;)

Mmm, not in my install. For Visual Studio 2005 version 8.0.50727.762
SP.050727-7600 on XP Pro, the default is False. Perhaps that's changed in
your version. Small bones, though!
 
JonOfAllTrades said:
Mmm, not in my install. For Visual Studio 2005 version 8.0.50727.762
SP.050727-7600 on XP Pro, the default is False. Perhaps that's changed in
your version. Small bones, though!

Nope, it has never changed since it was included in .Net 2.0. Visual Studio
does not change the default, and will display the default value as NON bold
text. You can also get the default if you completely remove the line setting
ShowItemToolTips from InitializeComponent.

Documentation also clearly states the default is true

http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstrip.showitemtooltips(VS.80).aspx
 
Morten Wennevik said:
Nope, it has never changed since it was included in .Net 2.0. Visual Studio
does not change the default, and will display the default value as NON bold
text. You can also get the default if you completely remove the line setting
ShowItemToolTips from InitializeComponent.

Documentation also clearly states the default is true

http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstrip.showitemtooltips(VS.80).aspx

That's nice. But *on my install*, the default is False. Yes, I noticed the
bold/not-bold thing, it would be hard to miss. And yes, I can create a new
project, add a StatusStrip, and the value will be False. It may be True for
every other install, but *on my install*, the default is False.
For whatever reason, others may somehow have a default set differently from
your computer, and for a newbie this could spell hours of confusion. To
believe that the "normal" defaults are always going to apply is an
assumption, and like all assumptions sooner or later it will be false.
 
Just if someone finds this thread via google, like I did, I want to add the solution.

Morten was wrong when writing:

> > No: it turns out that StatusStrip has a ShowItemToolTips property, which is
> > False by default. Changing this fixes the problem.
>
> Ah, I should have thought of that one. However, the default is True ...

The link given is about ToolStrip, JonOfAllTrades wrote about a StatusStrip. The correct link is:
.../en-us/library/system.windows.forms.statusstrip.showitemtooltips(v=vs.90).aspx (I'm unfortunately not allowed to post full links ;)

For a StatusStrip, ShowItemToolTips is false by default (like for a MenuStrip).
 
Back
Top