<legend id='LqbJV'><style id='LqbJV'><dir id='LqbJV'><q id='LqbJV'></q></dir></style></legend>

        <bdo id='LqbJV'></bdo><ul id='LqbJV'></ul>

    1. <small id='LqbJV'></small><noframes id='LqbJV'>

      <tfoot id='LqbJV'></tfoot>

      1. <i id='LqbJV'><tr id='LqbJV'><dt id='LqbJV'><q id='LqbJV'><span id='LqbJV'><b id='LqbJV'><form id='LqbJV'><ins id='LqbJV'></ins><ul id='LqbJV'></ul><sub id='LqbJV'></sub></form><legend id='LqbJV'></legend><bdo id='LqbJV'><pre id='LqbJV'><center id='LqbJV'></center></pre></bdo></b><th id='LqbJV'></th></span></q></dt></tr></i><div id='LqbJV'><tfoot id='LqbJV'></tfoot><dl id='LqbJV'><fieldset id='LqbJV'></fieldset></dl></div>

      2. 如何启动windows“运行"来自 C# 的对话框

        时间:2023-09-14

          <tbody id='yUgqz'></tbody>

        <small id='yUgqz'></small><noframes id='yUgqz'>

          <legend id='yUgqz'><style id='yUgqz'><dir id='yUgqz'><q id='yUgqz'></q></dir></style></legend>

          <tfoot id='yUgqz'></tfoot>

              <bdo id='yUgqz'></bdo><ul id='yUgqz'></ul>

                  <i id='yUgqz'><tr id='yUgqz'><dt id='yUgqz'><q id='yUgqz'><span id='yUgqz'><b id='yUgqz'><form id='yUgqz'><ins id='yUgqz'></ins><ul id='yUgqz'></ul><sub id='yUgqz'></sub></form><legend id='yUgqz'></legend><bdo id='yUgqz'><pre id='yUgqz'><center id='yUgqz'></center></pre></bdo></b><th id='yUgqz'></th></span></q></dt></tr></i><div id='yUgqz'><tfoot id='yUgqz'></tfoot><dl id='yUgqz'><fieldset id='yUgqz'></fieldset></dl></div>
                  本文介绍了如何启动windows“运行"来自 C# 的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在我的 C# 代码中从 Windows 启动运行对话框 (Windows+R).

                  I want to start the run dialog (Windows+R) from Windows within my C# code.

                  我认为这可以使用 explorer.exe 完成,但我不确定如何.

                  I assume this can be done using explorer.exe but I'm not sure how.

                  推荐答案

                  RunFileDlg API 不受支持,并且可能会被 Microsoft 从未来版本的 Windows 中删除(我将承认 MS 承诺向后兼容性以及该 API 虽然没有记录,但似乎广为人知的事实使得这不太可能,但仍有可能).

                  The RunFileDlg API is unsupported and may be removed by Microsoft from future versions of Windows (I'll grant that MS's commitment to backwards compatibility and the fact that this API, though undocumented, appears to be fairly widely known makes this unlikely, but it's still a possibility).

                  支持的启动运行对话框的方式是使用 IShellDispatch::FileRun 方法.

                  The supported way to launch the run dialog is using the IShellDispatch::FileRun method.

                  在 C# 中,您可以通过转到添加引用、选择 COM 选项卡并选择Microsoft Shell 控件和自动化"来访问此方法.完成此操作后,您可以按如下方式启动对话框:

                  In C#, you can access this method by going to Add Reference, select the COM tab, and select "Microsoft Shell Controls and Automation". After doing this you can launch the dialog as follows:

                  Shell32.Shell shell = new Shell32.Shell();
                  shell.FileRun();
                  

                  是的,RunFileDlg API 提供了更多的可定制性,但它的优点是可以记录和支持,因此将来不太可能中断.

                  Yes, the RunFileDlg API offers more customizability, but this has the advantage of being documented, supported, and therefore unlikely to break in the future.

                  请注意,Shell32 必须在 STA 线程上运行.如果代码中出现异常,请在方法声明上方添加 [STAThread],如下所示,例如:

                  Note that Shell32 must be run on an STA thread. If you get an exception in your code, add [STAThread] above your method declaration like this, for example:

                      [STAThread]
                      private static void OpenRun() {
                          //Shell32 code here
                      }
                  

                  任何调用使用 Shell32 的方法的方法也应该在 STA 线程上运行.

                  Any method calling a method that uses Shell32 should also be run on an STA thread.

                  这篇关于如何启动windows“运行"来自 C# 的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:WPF 多线程进度对话框 下一篇:“选择文件夹对话框"在 .NET 中

                  相关文章

                    <bdo id='nci7i'></bdo><ul id='nci7i'></ul>
                1. <legend id='nci7i'><style id='nci7i'><dir id='nci7i'><q id='nci7i'></q></dir></style></legend>

                  <i id='nci7i'><tr id='nci7i'><dt id='nci7i'><q id='nci7i'><span id='nci7i'><b id='nci7i'><form id='nci7i'><ins id='nci7i'></ins><ul id='nci7i'></ul><sub id='nci7i'></sub></form><legend id='nci7i'></legend><bdo id='nci7i'><pre id='nci7i'><center id='nci7i'></center></pre></bdo></b><th id='nci7i'></th></span></q></dt></tr></i><div id='nci7i'><tfoot id='nci7i'></tfoot><dl id='nci7i'><fieldset id='nci7i'></fieldset></dl></div>
                  <tfoot id='nci7i'></tfoot>

                  <small id='nci7i'></small><noframes id='nci7i'>