如何检查表单的状态 [英] How to Check Status of a Form

查看:104
本文介绍了如何检查表单的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目(Project1和Project2)

我已将project2添加到Project1中,并将Project2的参考添加到Project1。



如何检查Project2.Form1的状态..

实际上我想在关闭期间跟踪Project2.Form1 ...

表示Project2.Form1 geeting关闭

消息框将通过消息告诉我......表单正在关闭...

但是这个消息框我想从Project1.Form1运行。

在Project1.Form1中。我做了以下事情。



Imports Project2.Form1

Dim Prj2frm as Project2.Form1



现在我想跟踪它的结束状态....



如果Prj2frm越来越近......那么

Messagebox.show(表格正在关闭)

其他

没有

endif



请帮助....

I have two project (Project1 and Project2)
I have add project2 into Project1 and Also add Reference of Project2 to Project1.

How to check a status of Project2.Form1..
Actually I want to track Project2.Form1 during the time of closing...
means when Project2.Form1 geeting close
A messagebox will apprear... to me with message... Form is closing...
But This message box I want to run from Project1.Form1.
In Project1.Form1. I have did the following things.

Imports Project2.Form1
Dim Prj2frm as Project2.Form1

Now I want track its closing status....

If Prj2frm getting close... then
Messagebox.show("Form is closing")
else
nothing
endif

please help....

推荐答案

你的问题没有很好地制定,但很可能你需要这个:

http://msdn.microsoft。 com / en-us / library / system.windows.forms.form.formclosing%28v = vs.110%29.aspx [ ^ ]。



请注意,此事件允许您取消关闭,因此您可以根据条件执行此操作:

http://msdn.microsoft.com/en-us /library/system.windows.forms.formclosingeventargs%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system .windows.forms.formclosingeventargs.closereason%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.componentmodel .canceleventargs.cancel%28V = vs.110 %29.aspx [ ^ ]。



如果您需要别的东西,请不要怪我。学会准确提问,澄清是否需要。



请注意,UI开发的方法不同,这是面向事件的方法:你不检查状态,而不是处理事件。如果您对事件不太熟悉,那么您还没有准备好进行UI开发,首先,您需要学习事件。



-SA
Your problem is not well formulated, but, most likely, you need this:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing%28v=vs.110%29.aspx[^].

Note that this event allows you to cancel closing, so you can do it depending on condition:
http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs.closereason%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel%28v=vs.110%29.aspx[^].

If you needed something else, please don't blame me. Learn to ask questions accurately, clarify if you need to.

Note that the method of UI development is different, this is event-oriented approach: you don't "check status", instead, you handle events. If you are poorly familiar with events, you are not ready to do UI development, first, you need to learn events.

—SA


我认为这就是你要找的:

I think this is what you are looking for:
' Add Project Reference to Project2
Public Class Form1 ' Project1
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim Prj2Form1 As New Project2.Form1
      ' subscribe to the form's FormClosed event
      AddHandler Prj2Form1.FormClosed, AddressOf Project2FormClosed
      Prj2Form1.Show()
   End Sub

   Private Sub Project2FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
      If TypeOf sender Is Project2.Form1 Then
         Dim frm As Project2.Form1 = DirectCast(sender, Project2.Form1)
         ' unsubscribe from the form's FormClosed event
         RemoveHandler frm.FormClosed, AddressOf Project2FormClosed
         MsgBox("Project2 Form Closed")
      End If
   End Sub
End Class





请阅读: AddHandler [ ^ ]和 RemoveHandler [ ^ ]


这篇关于如何检查表单的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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