无法在WinForms中处置Form1 [英] Not able to dispose form1 in winforms

查看:59
本文介绍了无法在WinForms中处置Form1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有form1和form2.

每当登录(form1)成功时,我将导航到form2,然后在导航到form2之前试图关闭form1,这没有发生.我不确定这里缺少什么.

i have form1 and form2.

when ever the logins (form1) succeed then i will navigate to form2,before navigate to form2 am trying to close form1,that''s not happening.am not sure what am missing here.

 Login logform = new Login();
 logform.Dispose();
//i tried logform.close(), and this.close() (throwing error)
//Login successful then navigate to Form2.
DbNavigate.frmDataGridPaging form = new DbNavigate.frmDataGridPaging();
                    form.ShowDialog(this);


谢谢Advance


thanks in Advance

推荐答案

看来您的登录表单是应用程序的主要表单.应用程序主表单通常应保持活动状态,直到应用程序结束.

如果要在主表单之前显示表单,则应显示模式表单,并在完成后显示主表单.

无论如何,您必须重写一些代码,因为您的应用程序不遵循标准模式.

一个更简单的选项可能是先显示"true"应用程序,然后在显示时显示登录表单.

我认为问题在于应用程序仍希望使用登录表单,就像您调用的Application.Run(new Login());
一样.
您的代码很简单...但是您试图通过在应用程序结束之前不运行主表单"来做一些不寻常的事情.

动态更改主窗体需要一些技巧以使其正常工作,包括在任务栏中正确显示按钮...而无需移动或烦人的临时更改(2个按钮或在显示下一个窗体时不显示任何按钮).

因此,在实践中,如果您不遵循标准模式,则需要通过覆盖应用程序,应用程序上下文和表单中的适当方法(包括管理最后一个应用程序的关闭时间)来使其正常工作表单已关闭.
It appears that your login form is the application main form. The application main form should typically be kept alive until the application ends.

If you want to display a form before the main form, then you should display a modal form and when done display the main form.

Anyway for that purpose, you would have to override some code as your application does not follows the standard pattern.

A simpler option might be to display the "true" application first and when shown display the login form.

I would think that the problem is that the application still want to uses the login form as you have called Application.Run(new Login());

Your code is simple... but you are trying to do something unusual by not having your "main form" alive until your application ends.

Changing the main form dynamically need some tricks to make it works properly including proper display of button in the task bar... without move or annoying temporary changes (2 buttons or no button for while displaying the next form).

Thus in pratice, if you don''t follow the standard pattern, it will be up to you to make it work by overriding the appropriate methods in the application, the application context and your form including managing the closing of the application when the last form is closed.


您不想在关闭时从中创建登录对象.只需在第一行中编写this.close(),然后调用cal form2.
试试这个.
You don''t want to create object of login from while closing. Just you write this.close() in the first line and call then cal form2.
Try this.
this.close()
//Login successful then navigate to Form2.
DbNavigate.frmDataGridPaging form = new DbNavigate.frmDataGridPaging();
                    form.ShowDialog(this);


尝试this.Close();


这篇关于无法在WinForms中处置Form1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆