我正在尝试创建一个Windows移动应用程序,由于某种原因,SuspendLayout一直在崩溃。
崩溃是怎么回事。我转到我的应用程序的登录页面。然后我将手机旋转到横向并登录。
然后我按下“确定”按钮,该按钮应该关闭我去的新表格。然后我回到登录页面,然后将手机旋转回纵向模式。然后我从表格(我刚关闭的那个)得到了期望。
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()
修改
当方向改变或横向为真时,我会调用它。由于某人可能会在登录表单上轮换,因此我的所有表单都必须调整为旋转。
所以我有类似的东西
//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();
}
如果用户再次更改轮换(或第一次在该表单上),将调用SystemState.Change is事件。这会调用SetLayout()。
答案 0 :(得分:1)
我的猜测是您在表单上注册了该事件(“PhoneRotated”),并且在关闭表单之前没有取消注册。因此,当事件触发时,您的已关闭表单会收到通知,但无法执行SuspendLayout,因为您已经关闭它。