form_unload [英] form_unload

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

问题描述

关闭表单时,如何运行代码?我知道我可以有一个

按钮并将代码放在那里然后关闭表单,但是当我点击X时,我需要运行
代码

表格的右上角。在VB6中我认为它是form_unload事件,但是在C#中似乎不是
。我错过了什么?

谢谢

Ringo

解决方案

Ringo写道:


如何在关闭表单时运行代码?我知道我可以有一个

按钮并将代码放在那里然后关闭表单,但是当我点击X时,我需要运行
代码

表格的右上角。在VB6中我认为它是form_unload事件,但是在C#中似乎不是
。我错过了什么?



您可以处理Closing或Closed事件(或覆盖OnClosing或

OnClosed)。有什么不同? OnClosing发生在表单关闭之前

并且如果你想这样做,你可以选择取消关闭。

OnClosed发生任何取消行动的机会。

-

汤姆波特菲尔德


我创造了一个功能:

private void Form1_Closing(object sender,

System.ComponentModel.CancelEventArgs e)

{

MessageBox.Show("我正在关闭) ;);

Console.Write(关闭通信);

}


但我不是知道如何在表单关闭时触发它吗?

谢谢

Ringo


Tom Porterfield写道:


Ringo写道:


如何在关闭表单时运行代码?我知道我可以有一个

按钮并将代码放在那里然后关闭表单,但是当我点击X时,我需要运行
代码

表格的右上角。在VB6中我认为它是form_unload事件,但是在C#中似乎不是
。我错过了什么?



您可以处理Closing或Closed事件(或覆盖OnClosing或

OnClosed)。有什么不同? OnClosing发生在表单关闭之前

并且如果你想这样做,你可以选择取消关闭。

OnClosed发生任何取消行动的机会。

-

Tom Porterfield


2007年1月8日15:01:02 -0800," ;林檎" < ri ********* @ gmail.comwrote:


>我创建了一个函数:

private void Form1_Closing(对象发送者,
System.ComponentModel.CancelEventArgs e)

{

MessageBox.Show(我正在关闭);

Console.Write(关闭通信);

}

但我不知道如何在表单中触发它关闭?
谢谢
Ringo

Tom Porterfield写道:


> Ringo写道:
< blockquote class =post_quotes>
如何在关闭表单时运行代码?我知道我可以有一个

按钮并将代码放在那里然后关闭表单,但是当我点击X时,我需要运行
代码

表格的右上角。在VB6中我认为它是form_unload事件,但是在C#中似乎不是
。我错过了什么?


您可以处理Closing或Closed事件(或覆盖OnClosing或
OnClosed)。有什么不同? OnClosing发生在表单关闭之前
并且如果你想这样做,你可以选择取消关闭。
OnClosed发生任何取消行动的机会。
-
汤姆波特菲尔德



如果你没有订阅这个活动就不会开火。创造它并不是你所需要的全部。阅读有关事件的文档,看看你是否可以弄清楚

如何使用它们。如果不再问。

祝你的项目顺利,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com


How do I get code to run when I close a form? I know I can have a
button and put the code there then close the form that way, but I have
code that needs to run when the user clicks the X in the upper right of
the form. In VB6 I think it is the form_unload event, but that does not
seem to be the case in C#. What am I missing?
Thanks
Ringo

解决方案

Ringo wrote:

How do I get code to run when I close a form? I know I can have a
button and put the code there then close the form that way, but I have
code that needs to run when the user clicks the X in the upper right of
the form. In VB6 I think it is the form_unload event, but that does not
seem to be the case in C#. What am I missing?

You can either handle the Closing or Closed event (or override OnClosing or
OnClosed). What''s the difference? OnClosing occurs before the form closes
and gives you the option of cancelling the close if you want to do so.
OnClosed occurs past any opportunities to cancel the action.
--
Tom Porterfield


I created a funtion:
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("I''m closing");
Console.Write("shutting down communication");
}

but I don''t know how to get it to fire when the form closes?
Thanks
Ringo

Tom Porterfield wrote:

Ringo wrote:

How do I get code to run when I close a form? I know I can have a
button and put the code there then close the form that way, but I have
code that needs to run when the user clicks the X in the upper right of
the form. In VB6 I think it is the form_unload event, but that does not
seem to be the case in C#. What am I missing?


You can either handle the Closing or Closed event (or override OnClosing or
OnClosed). What''s the difference? OnClosing occurs before the form closes
and gives you the option of cancelling the close if you want to do so.
OnClosed occurs past any opportunities to cancel the action.
--
Tom Porterfield


On 8 Jan 2007 15:01:02 -0800, "Ringo" <ri*********@gmail.comwrote:

>I created a funtion:
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("I''m closing");
Console.Write("shutting down communication");
}

but I don''t know how to get it to fire when the form closes?
Thanks
Ringo

Tom Porterfield wrote:

>Ringo wrote:

How do I get code to run when I close a form? I know I can have a
button and put the code there then close the form that way, but I have
code that needs to run when the user clicks the X in the upper right of
the form. In VB6 I think it is the form_unload event, but that does not
seem to be the case in C#. What am I missing?


You can either handle the Closing or Closed event (or override OnClosing or
OnClosed). What''s the difference? OnClosing occurs before the form closes
and gives you the option of cancelling the close if you want to do so.
OnClosed occurs past any opportunities to cancel the action.
--
Tom Porterfield

If you don''t subscribe to the event it won''t fire. Creating it is not all you
have to do. Read the documentation on Events and see if you can figure out how
to use them. If not ask again.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com


这篇关于form_unload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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