目前已经实现了通过Click事件开关子窗体,但是一开就变了,而且开了之后如果用ToolStripMenuItem的checked属性来控制开关没问题,可是手动关闭了子窗体后,再点击,就会抛出异常未处理
System.ObjectDisposedException
Message="无法访问已释放的对象。\r\n对象名:“Form2”。"
Source="System.Windows.Forms"
ObjectName="Form2"
StackTrace:
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Form.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Control.Show()
在 ActionEditer.Form1.打开预览窗口() 位置 E:\Projects\VS Projects\ActionEditer\ActionEditer\Form1.cs:行号 28
在 ActionEditer.Form1.动画ToolStripMenuItem_Click(Object sender, EventArgs e) 位置 E:\Projects\VS Projects\ActionEditer\ActionEditer\Form1.cs:行号 154
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 ActionEditer.Program.Main() 位置 E:\Projects\VS Projects\ActionEditer\ActionEditer\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
在 System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
在 System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: -----------------------------------------------------
以下是我的代码
----------------------------------------------------- public Form2 fm2;
public Form1()
{
InitializeComponent();
this.IsMdiContainer = true;
fm2 = new Form2();
this.打开预览窗口();
}
private void 打开预览窗口()
{
if (fm2 != null)
{
fm2.Show();
}
} private void 关闭预览窗口()
{
fm2.Hide();
}
private void 动画ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.动画ToolStripMenuItem.Checked = !this.动画ToolStripMenuItem.Checked;
if (this.动画ToolStripMenuItem.Checked)
{
this.打开预览窗口();
}
else
{
this.关闭预览窗口();
}
}我最终想实现的一个功能就像是PhotoShop里面那些图层,信息之类的子窗体的控制一样。
恳请各位大哥帮帮忙
System.ObjectDisposedException
Message="无法访问已释放的对象。\r\n对象名:“Form2”。"
Source="System.Windows.Forms"
ObjectName="Form2"
StackTrace:
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Form.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Control.Show()
在 ActionEditer.Form1.打开预览窗口() 位置 E:\Projects\VS Projects\ActionEditer\ActionEditer\Form1.cs:行号 28
在 ActionEditer.Form1.动画ToolStripMenuItem_Click(Object sender, EventArgs e) 位置 E:\Projects\VS Projects\ActionEditer\ActionEditer\Form1.cs:行号 154
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 ActionEditer.Program.Main() 位置 E:\Projects\VS Projects\ActionEditer\ActionEditer\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
在 System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
在 System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: -----------------------------------------------------
以下是我的代码
----------------------------------------------------- public Form2 fm2;
public Form1()
{
InitializeComponent();
this.IsMdiContainer = true;
fm2 = new Form2();
this.打开预览窗口();
}
private void 打开预览窗口()
{
if (fm2 != null)
{
fm2.Show();
}
} private void 关闭预览窗口()
{
fm2.Hide();
}
private void 动画ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.动画ToolStripMenuItem.Checked = !this.动画ToolStripMenuItem.Checked;
if (this.动画ToolStripMenuItem.Checked)
{
this.打开预览窗口();
}
else
{
this.关闭预览窗口();
}
}我最终想实现的一个功能就像是PhotoShop里面那些图层,信息之类的子窗体的控制一样。
恳请各位大哥帮帮忙
解决方案 »
- 有没哪个高手教一下 随机数怎么写
- 动态生成的DataGridView列标题显示问题
- 使用httpWebRequest请求URL时,访问本页面,您的浏览器需要支持JavaScript
- 最后几十分了,求教dataset中主从表更新的问题,做过的请进来看看。。。。。。。。。。。。。。。。。
- 一个对大家可能很简单的问题!!!拜托啦!!
- framwork 2.0和1.1 的兼容性问题,急啊!
- 在C#中,把DataGrid中的数据导出为Excel时,出现了数据ID号,如1000003300555,显示为了数据形式:1.33+e的形式,如何解决
- 如何保证要上传的文件 在客户端文件必须存在
- 那一位有邮件系统的源代码(1000分送)
- Winform发信正常 ,IIS 无法发信
- C#我用webbrowser的DrawToBitmap抓图为什么是空白的
- 新人关于UDP编程的疑问,请大家指教!
这肯定不对了,
定义form2的父窗体是当前窗体
form2 frm2=new form2();//实例化form2
frm2.mdiparent=this;//form2的父窗体是当前窗体
frm2.show();//显示子窗体form2时的语句