如何在按钮单击时关闭 .exe 应用程序 [英] how to close .exe application on button click

查看:82
本文介绍了如何在按钮单击时关闭 .exe 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何使用 c# 在单击按钮时关闭 .exe 文件.我知道如何使用 c# 在按钮单击时运行 .exe 文件,如下所示:

Can any one tell me how can I close .exe file on button click using c#. I've got an idea of how to run .exe file on button click using c# as follows:

string str = @"C:\windows\system32\notepad.exe";
process.StartInfo.FileName = str;
process.Start();

但是谁能告诉我如何在 c# 中单击按钮时关闭 .exe 应用程序?

But can anyone tell me how to close .exe application on button click in c#?

推荐答案

我认为您想调用 CloseMainWindow()Process 上.这类似于单击窗口的关闭按钮,因此它实际上可能不会关闭应用程序.

I think you want to call CloseMainWindow() on the Process. This is analogous to clicking on the close button of the window, so it may not actually close the application.

例如,如果用户在窗口中编辑了一些文本,但没有保存,这将显示您要保存更改吗?"对话框.

For example, if the user edited some text in the window, but didn't save it, this will show the "Do you want to save your changes?" dialog.

如果你想真正关闭应用程序,无论如何都可以使用Kill().这可能会导致数据丢失(不会保存对文件所做的编辑),但这对您来说可能不是问题.

If you want to really close the application, no matter what, you can use Kill(). This may cause loss of data (the edits to the file won't be saved), but that may not be a problem for you.

这篇关于如何在按钮单击时关闭 .exe 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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