如何告诉另一个表格关闭的表格[复制](How to tell a form that another form Closes [duplicate])

编程入门 行业动态 更新时间:2024-10-22 16:28:56
如何告诉另一个表格关闭的表格[复制](How to tell a form that another form Closes [duplicate])

这个问题在这里已经有了答案:

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 answer

I 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.

更多推荐

本文发布于:2023-08-05 17:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437446.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表格   form   duplicate   Closes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!