Windows Forms Application Crashes When Calling ToolTip.SetToolTip Method for Associated TreeView control

Article translations Article translations
Close Close
Article ID: 953102 - View products that this article applies to.
Expand all | Collapse all
Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action

You have developed a Microsoft .NET Framework 2.0 Windows Forms application which contains a ToolTip control and a Treeview control. The application calls the ToolTip control’s SetToolTip method multiple times, for example, in the MouseMove event of the TreeView Control; and passes the Treeview control as the first parameter to the SetToolTip method.

Result



When hovering the mouse over a Node in the TreeView control, the ToolTip may not display all the text specified in the SetToolTip method. When exiting the application, you may also receive the following error:

Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Environment.GetResourceFromDefault(String key)
   at System.ObjectDisposedException..ctor(String objectName)
   at System.Windows.Forms.Control.DestroyHandle()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.Form.Dispose(Boolean disposing)
   at WindowsFormsApplication1.Form1.Dispose(Boolean disposing) in C:\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 20
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Form.WmClose(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

If you are debugging the application in Visual Studio, you may receive the following MDA error when exiting instead of the System.AccessViolationException above. 

FatalExecutionEngineError was detected

The runtime has encountered a fatal error. The address of the error was at <address>, on thread <thread>. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

Cause

The TreeView control's ShowNodeToolTips property is set to True to enable built-in tooltips for the nodes in the TreeView control. This conflicts with the tooltip being created by the ToolTip control's SetToolTip method.

Resolution



You can use one of the following solutions to work around this problem.

1. Set the TreeView control's ShowNodeToolTips property to False. This is the easiest solution if the intent is to use the ToolTip control for displaying ToolTips instead of the TreeView control's built-in Node ToolTips (the ToolTip control has some additional features not exposed by the TreeView control's ToolTip implementation).

2. Alternatively, you can remove the call to the ToolTip control's SetToolTip method, and use the TreeView control's built-in ToolTips. To do this, you must make sure that the TreeView control's ShowNodeToolTips property is set to True, and that you have set each TreeNode's ToolTipText property to the desired value.

More Information



STEPS TO REPRODUCE
====================

1. Using Visual Studio 2005 or Visual Studio 2008, create a new C# Windows Forms application.
2. Add a TreeView control to the form named "treeView1".
3. Set the TreeView control's ShowNodeToolTips property to True.
4. Add a ToolTip control to the form named "toolTip1".
5. Add the following code to the form's Load event handler:

  private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                TreeNode newNode = new TreeNode();
                newNode.Text = "test node " + i.ToString();
                newNode.Tag = i.ToString();
                treeView1.Nodes.Add(newNode);
            }
        }

6. Add the following code to the MouseMove event handler of the TreeView control:

  private void treeView1_MouseMove(object sender, MouseEventArgs e)
        {
            TreeView tv = sender as TreeView;
            if (tv != null)
            {
                TreeNode tn = tv.GetNodeAt(new Point(e.X, e.Y));
                if (tn != null)
                {
                    this.toolTip1.SetToolTip(tv, tn.Text);
                }
            }
        }

7. Build the application and run it.
8. Hover the mouse over several nodes in the TreeView control.
9. Close the form to exit the application.

You should receive one of the errors listed in the Result section above.



When running the application under a native code debugger, you may also see an Access Violation occurring in the following call stack.



mscorlib_ni!System.Runtime.InteropServices.Marshal.PtrToStructure(IntPtr, System.Type)+0x5d
System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(IntPtr, System.Type)+0x25
System_Windows_Forms_ni!System.Windows.Forms.TreeView.WmNeedText(System.Windows.Forms.Message ByRef)+0x35
System_Windows_Forms_ni!System.Windows.Forms.TreeView.WndProc(System.Windows.Forms.Message ByRef)+0x36e281
System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)+0xd
System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)+0x36
System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0x5a
user32!InternalCallWinProc+0x23
user32!UserCallWinProcCheckWow+0x14b
user32!CallWindowProcAorW+0x97
user32!CallWindowProcW+0x1b
comctl32!CallOriginalWndProc+0x1a
comctl32!CallNextSubclassProc+0x3c
comctl32!DefSubclassProc+0x46
comctl32!TTSubclassProc+0x59
comctl32!CallNextSubclassProc+0x3c



DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

Properties

Article ID: 953102 - Last Review: May 13, 2008 - Revision: 1.1
APPLIES TO
  • Microsoft .NET Framework 2.0
Keywords: 
kbnomt kbrapidpub KB953102

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com