开发者

Control what red x does on window using wpf forms in c#

开发者 https://www.devze.com 2023-01-27 12:55 出处:网络
I am currently developing an application in c# using wpf. I would like to control what the red x (close window) does. At the moment, I press the red x and it closed the current window and continues ru

I am currently developing an application in c# using wpf. I would like to control what the red x (close window) does. At the moment, I press the red x and it closed the current window and continues running the rest of the program. I do not want this to h开发者_运维技巧appen. Instead when the x is pressed I want the whole program to finish.

Can this be done?

Thanks for your help


You want to do some event handling on the Window.Closed event, or override the Window.OnClosed method and put the code to shutdown the program in there.

http://msdn.microsoft.com/en-us/library/system.windows.window.onclosed.aspx


An alternative to DGH's answer can also be found on codeproject's website


You probably want to trap the closing of the form, and set a global such as "stopRequested", that other parts of the program should check while looping. See http://msdn.microsoft.com/en-us/library/system.windows.forms.form.closing.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消