这个问题在这里已经有了答案:
Winform表单关闭事件 1的答案我有称为“GameForm”的“form1”。 它发送的东西是这样的:
var tmp = new Pjeu(P1, P2); tmp.Show();两个“P”都是一类。 在“GameForm”中,它最终找到了胜利者并且像这样关闭自己:
MessageBox.Show("Victory " + label3.Text, "Game Finished", MessageBoxButtons.OK); this.Close();我怎样才能让“Form1”知道它已关闭? 我需要两次进行比赛才能找到2个赢家,所以我需要我的第一个表格来做两次游戏,然后等待它关闭以创建另一个。 我找到了一些答案,但没有在我的情况下工作。
This question already has an answer here:
Winform form closed event 1 answerI have "form1" that calls "GameForm". It sends stuff to is like such:
var tmp = new Pjeu(P1, P2); tmp.Show();Both "P" are a class. In the "GameForm", it eventually finds a winner and closes itself like such:
MessageBox.Show("Victory " + label3.Text, "Game Finished", MessageBoxButtons.OK); this.Close();How can i make the "Form1" know that it has closed? I need to do the Game twice to find 2 winner so i need my first form to do the game twice and wait for it to be closed to make another one. I found some answers but none that worked in my context.
最满意答案
在你的GameForm中,你可以创建一个自定义事件,并在表单关闭之前提升它。 并且在Form1中只需订阅此事件。
在GameForm中:
public delegate void Winner(); public event Winner OnWinnerFound; ... OnWinnerFound(); // Just call your event MessageBox.Show("Victory " + label3.Text, "Game Finished", MessageBoxButtons.OK); this.Close();在你的Form1中:
var tmp = new Pjeu(P1, P2); tmp.OnWinnerFound+=WinnerFound; tmp.Show(); ... private void WinnerFound() { //Your code here }我不记得,也许有一个内置的事件,当表单关闭或表单关闭时发生。
in your GameForm you can create a custom event and rise it before form is closed. And in your Form1 just subscribe for this event.
In GameForm:
public delegate void Winner(); public event Winner OnWinnerFound; ... OnWinnerFound(); // Just call your event MessageBox.Show("Victory " + label3.Text, "Game Finished", MessageBoxButtons.OK); this.Close();In your Form1:
var tmp = new Pjeu(P1, P2); tmp.OnWinnerFound+=WinnerFound; tmp.Show(); ... private void WinnerFound() { //Your code here }I don't remember, maybe there is a built in event, which occurs when form is closed or form is closing.
更多推荐
发布评论