如何从combox运行应用程序 [英] How do I get an app to run from a combox

查看:100
本文介绍了如何从combox运行应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这也许是我能想象到的最不寻常的帮助请求之一,我希望能有所帮助。



我是目前正在使用Visual Studio 2013 Express版本,并使用C#。



我正在开发一个可以运行加载到组合框中的安装程序的程序。这使得它比为各个安装程序提供大量按钮更加整洁。这也给分销商提供了他希望分发的安装程序,并使用该程序来运行它们。



到目前为止,我已经成功地让安装程序加载到他们各自的组合框,并没有问题,但问题是从一个组合执行(运行)加载安装程序。



我曾经尝试过的代码让安装程序运行是:



This is perhaps the one of the most unusual request for help that I can imagine, and I hope with bated breath you are able to help.

I am currently using Visual Studio 2013 Express edition, and using C#.

I am developing a program that can run installers loaded into a combobox. This makes it a lot tidier than having a lot of buttons for individual installers. Also this gives a distributor to have installers he wishes to distribute, and use this program to run them.

So far I've succeeded in getting the installers to load into their respective combo boxes, and have no issues here, but the problem is getting a loaded installer to execute (run) from the combo.

The code I used to try to get the installers to run is:

Using System.Diagnostics;

private void cmbBibles_SelectedIndexChanged(object sender, EventArgs e)
{
    Process prcBibles=new Process();

    prcBibles.StartInfo=new ProcessStartInfo(cmbBibles.SelectedItem);
    prcBibles.StartInfo.UseShellExecute=true;
    prcBibles.Start();
}





上面的代码是我在StackOverflow和VS帮助中找到的解决方案。但是在运行程序时,我遇到了一堆错误。



我希望你能帮助我找到一些非常好的解决方案来实现这个目标。



亲切的问候,

Stephen。



The above code is a solution I found on StackOverflow, and in VS help. But when running the program I get a heap of errors.

I hope you can help with some really good solutions to get this running.

Kind Regards,
Stephen.

推荐答案

我尝试使用进程。开始,它似乎工作正常。



I tried using Process.Start and it seems to be working fine.

using System.Diagnostics; 
//...
string myEXE = cmbBibles.SelectedItem.ToString();
Process.Start(myEXE);





但是comboBox必须具有要运行的可执行文件的完整路径。 br />
您可以通过以下方式显示可执行文件的名称:创建列表< string>< / string> ,添加完整路径,并使用 Path.GetFileNameWithoutExtension(); 仅显示comboBox中的名称。



希望这有帮助 - CCB



But the comboBox must have the full path of your executable file to run.
You can show just the names of the executable files by: Creating a List<string></string>, adding the full paths to it, and use Path.GetFileNameWithoutExtension(); to show only names in the comboBox.

Hope this helps - CCB


参见 https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo%28v=vs.110%29 .aspx [ ^ ]和 https://msdn.microsoft.com/en-us/library/system.diagnostics.process%28v=vs.110%29.aspx [ ^ ]。您需要检查是否为这些方法提供了有效的参数详细信息。
See https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo%28v=vs.110%29.aspx[^], and https://msdn.microsoft.com/en-us/library/system.diagnostics.process%28v=vs.110%29.aspx[^]. You need to check that you are providing valid parameter details to these methods.


这篇关于如何从combox运行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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