Microsoft Bug Resolution: System.objectdisposedexception: Unable to access the disposed object. Object name: "Icon"

Source: Internet
Author: User

In WinForm development, the following exceptions often occur when multiple MDI forms are opened and the form is closed in a maximized state:

System.objectdisposedexception: Unable to access the disposed object.
Object name: "Icon".
In System.Drawing.Icon.get_Handle ()
In System.Drawing.Icon.get_Size ()
In System.Drawing.Icon.ToBitmap ()
In System.Windows.Forms.MdiControlStrip.GetTargetWindowIcon ()
In System.Windows.Forms.MdiControlStrip. ctor (IWin32Window target)
In System.Windows.Forms.Form.UpdateMdiControlStrip (Boolean maximized)
In System.Windows.Forms.Form.UpdateToolStrip ()
In System.Windows.Forms.Form.OnMdiChildActivate (EventArgs e)
In System.Windows.Forms.Form.ActivateMdiChildInternal (Form form)
In System.Windows.Forms.Form.WmMdiActivate (message& m)
In System.Windows.Forms.Form.WndProc (message& m)
In System.Windows.Forms.Control.ControlNativeWindow.OnMessage (message& m)
In System.Windows.Forms.Control.ControlNativeWindow.WndProc (message& m)
In System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, INTPTR wparam, INTPTR lparam)

This is a bug in the. NET Framework, and the current solution is:

Put here code in your MDI child formclosing Event

Critical code

This. WindowState = Formwindowstate.normal;

Set Formwindowstate.normal, the system automatically sets all subforms to Formwindowstate.normal state and requires the following code to restore

If there are currently only 3 forms (the primary Workbench, the form currently being closed, another form), the other form maximizes
foreach (Form frm in MdiForm.MdiParent.MdiChildren)
if (frm. Equals (This) = = False)
frm. WindowState = formwindowstate.maximized;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.