views:

75

answers:

1

Hi

I am trying to make a windows mobile application and for some reason the SuspendLayout keeps crashing.

How it is crashing is this. I go to my login page for my app. I then rotate the phone to landscape and login.

I then press the "OK" button that should close this new form I went to. I then am back to the the login page and I rotate the phone back to portrait mode. I then get an expect from the form(the one I just closed up).

System.ObjectDisposedException was unhandled
  Message=""
  ObjectName=""
  StackTrace:
       at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)
       at System.Windows.Forms.Control.get_Bounds()
       at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)
       at System.Windows.Forms.Control.SuspendLayout()
       at MiniPlannerWM.Views.Shared.PlannerForms.Planner.SetLayOut()
       at MiniPlannerWM.Views.Shared.PlannerForms.Planner.orientationChange_Changed(Object sender, ChangeEventArgs args)
       at Microsoft.WindowsMobile.Status.SystemState.RegistryState_ChangeOccured(Object sender, ChangeEventArgs args)
       at Microsoft.WindowsMobile.Status.RegistryState.notificationWindow_Changed(Object sender, ChangeEventArgs args)
       at Microsoft.WindowsMobile.Status.NotificationWindow.WndProc(Message& msg)
       at Microsoft.WindowsCE.Forms.MessageWindow._WndProc(Message& msg)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at MiniPlannerWM.Program.Main()

Edit

I call the it when the orientation changes or when landscape is true. Since a person might rotate on the login form so all my forms have to adjust to for the rotation.

so I have something like this

//login


form_load
{
   //figure out if they rotated this will be figured out by the SystemState.Change event that calls SetLayout that determine if they are in landscape or portrait.
   // set landscape property to true if they are in landscape mode.
}


// form1
form_load
{
  // generate default layout(formed for portrait)
  // if landscape property is set to true Call SetLayout
  // other wise just keep in default layout mode.

}

SetLayout()
{
  SuspendLayout();
  // code to determine if they are in portrait mode or landscape mode
  // once determined change sizes and stuff for new mode.
  // set static landscape property to true or false to use for future forms.
  ResumeLayout();
}

If user changes rotation again(or the first time on that form) the SystemState.Change is event will be called. This calls the SetLayout().

+1  A: 

My guess is that you registered for the event ("PhoneRotated") on the form, and didn't un-register it before closing the form. So when event fires your closed form receives notification, but fails to execute SuspendLayout, because you already closed it.

how do I un-register this?
chobo2
LaserCharger.LaserFired -= new EventHandler(HandleLaserFiring);
So you think I should remove the SystemState.Change?
chobo2
you need to unregister `orientationChange_Changed`. I do not know what event exactly it handles. Just call the same line you used to register `orientationChange_Changed`, but use -= instead of +=