ToolTip stops working after I dismiss the window once

J

Jim H

I have a dialog that I bring up as an options dialog. I have a variable for
this dialog as a member of the main application form and I create it in the
constructor. I bring up the dialog by calling
MyOptionsDialog.ShowDialog(this) and I check the DialogResult in an if
statement.

The dialog has an owner draw ListBox that contains some UserControls I
created. Each of those controls has a TooTip in it. The tool tip works
fine the first time I call ShowDialog, but every time it gets called after
that there are no tool tips for the items in the ListBox of the dialog.
Everything else about it works fine, I can click the UserControls and scroll
the ListBox. I know I must be doing something wrong. I tried catching the
Closing message and setting the e.Cancel property to true to see if it would
make a difference, but it did not.

Any ideas? Is there a way to reinitialize the tool tip? I tried putting
calls to SetToolTip in the OnVisibleChanged event of the UserControl but
that doesn't help.

Thanks,
jim
 
K

Kevin Yu [MSFT]

Hi Jim,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that the tooltip is not showing correctly in
your owner draw listbox. If there is any misunderstanding, please feel free
to let me know.

I have tried it with the code you have sent me last time. I added a tooltip
object and set tooltips when the usercontrol GaugeStyleSelect loads.

this.toolTip1.SetToolTip(this.m_chkUseGauge, "Hello");
this.toolTip1.SetToolTip(this.m_rbAnalog, "Hello");
this.toolTip1.SetToolTip(this.m_rbDigital, "Hello");

However, it works fine on my computer when I open and close the dialog box
again and again. Could you let me know where did you add the tooltip to
controls? Or could you show us some of the code? Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
J

Jim H

I added the tooltip on the usercontrol GaugeStyleSelect, just like the
project I sent you. I create the dialog once in the main form and keep
reusing that dialog. The Apply button has its DialogResult property set to
"OK". In the test app I sent you the dialog is created and displayed in the
OnTestClick from "button1". In my real app it is created in the constructor
of the main form and there is a menu item that has a Clicked event that
calls m_AlreadyCreatedGaugeOptDlg.ShowDialog(this).

The first time that object is displayed by calling ShowDialog tooltips work
fine. The next time that same dialog object is dispayed, using
ShowDialog(this), the tool tips no longer work.

The code in Form1.cs looks like this:
private GaugeOptions lDlg = new GaugeOptions();

private void OnTestClick(object sender, System.EventArgs e)
{
lDlg.ShowDialog(this);
}


Jim
 
K

Kevin Yu [MSFT]

Hi Jim,

I have reproduced it and is researching on it. Will post back ASAP. Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Jim,

Based on my research, it seems that this is the default behavior of windows
forms. I assume that you're calling SetToolTip in Form.Load event. However,
if the Form object is not disposed, the Load event will not be fired again.
So, the tooltip is not shown. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
J

Jim H

Why does it go away in the first place? Is there a way to prevent this?
How do I go about getting them back?

jim
 
K

Kevin Yu [MSFT]

Hi Jim,

The first time the form is loaded, Form.Load event is fired. However, the
second time, it is not fired again since we didn't "new" the object.
Currently I haven't found a workaround to prevent this. Could you try to
dispose the form and new it again?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top