关闭当前表单并在WinForm应用程序中打开新表单 [英] Close current form and open new form in WinForm Applications

查看:74
本文介绍了关闭当前表单并在WinForm应用程序中打开新表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有5种形式:frmLogin,frmOptionSelect,frmMenu,frmStaff和frmCompany

第一个启动表单是frmLogin.登录后,用户将转到frmOptionSelect.我编写的代码是将frmOptionSelect变暗为新表格,并显示该表格和Me.hide.这也是我在frmOptionSelect中制作的,以调用frmMenu.

好的,我在frmMenu上添加了2个按钮; btnStaffDet和btnCompny.当用户单击btnStaffDet时,我将调用frmStaffDetails并将其放置在frmMenu上.这是我的代码:

Hi all,

I have a 5 forms: frmLogin, frmOptionSelect, frmMenu, frmStaff and frmCompany

The first startup form is frmLogin. After login, user will go to frmOptionSelect. The code I made is Dim the frmOptionSelect as new form,show the form and Me.hide. This also I made in frmOptionSelect to call frmMenu.

Ok, on frmMenu I add 2 button; btnStaffDet and btnCompny. When user click btnStaffDet, I will call frmStaffDetails and place it onto the frmMenu. This is my code:

Private Sub btnStaffDet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStaffDet.Click

     Dim frmStaffDet As New frmStaffDetails()
     frmStaffDet.TopLevel = False
     Me.Controls.Add(frmStaffDet)
     checkOpenForm(frmStaffDet)
     frmStaffDet.Show()
     frmStaffDet.Location = New Point(2, 149)

End Sub



checkOpenForm 用于检查在frmMenu上打开了哪个表单,如果有,它将关闭并在其上显示被调用的表单.这是检查任何打开的表单的代码:



The checkOpenForm is use to check which form is open on frmMenu.If there is any, it will close it and display the called form on it. This is the code for checking any opened form:

Private Sub checkOpenForm(ByRef openform As Windows.Forms.Form)

   For i As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
       If My.Application.OpenForms.Item(i) IsNot Me Then
           My.Application.OpenForms.Item(i).Close()
       End If
   Next i

End Sub




现在,有人可以引导我找到正确的代码,它只会检查frmMenu中的打开表单,而不是整个应用程序吗?因为现在,当它检查打开的窗体时,它会检查登录"和选项选择"窗体,并且由于它只隐藏,因此将关闭窗体,但菜单"窗体中不显示任何内容.请帮助..




Right now, could anyone lead me to the right code which it will only check the open form in frmMenu and not the whole apps? Because right now, when it check the open forms, it check the Login and Option Select form and because it only hide, it will close the forms but nothing displayed in Menu form. Please help..

推荐答案

也许可以为您提供帮助
在frmMenu下面显示窗体时,例如frmStaff和frmCompany,应使用以下代码:
frmStaff.Show(Me)
我"是表格frmMenu,将在执行过滤器checkOpenForm时使用.
使用属性所有者"在调用函数checkOpenForm时查看谁是他的父母.
"OpenForms(x).所有者()"

请参阅以下代码以检查表格

私人子checkOpenForm(ByRef openform作为FormCollection)
作为新的Form1 Dim formParent
关于错误继续下一个
作为openform中每个oForm的表单
如果oForm.Owner不是formParent oForm.Owner不是Nothing那么
oForm.Close()
其他
oForm.Show()
结束If
下一个
formParent.Dispose()
结束Sub
maybe this can help you
when displaying the form below frmMenu, such frmStaff and frmCompany, you should use the following code:
frmStaff.Show (Me)
"Me" is a form frmMenu, will be used when performing filter checkOpenForm.
use the property "Owner" to see who his parents when calling the function checkOpenForm,
"OpenForms (x). Owner ()"

See the following code to check the form

Private Sub checkOpenForm (ByRef openform As FormCollection)
As New Form1 Dim formParent
On Error Resume Next
As Form For Each oForm In openform
And if oForm.Owner isnot formParent oForm.Owner isnot Nothing Then
oForm.Close ()
else
oForm.Show ()
end If
Next
formParent.Dispose ()
end Sub


这篇关于关闭当前表单并在WinForm应用程序中打开新表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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