从MenuStrip启动控制台应用程序(Visual C#)(Launching a Console Applications from a MenuStrip (Visual C#))

编程入门 行业动态 更新时间:2024-10-27 18:31:52
从MenuStrip启动控制台应用程序(Visual C#)(Launching a Console Applications from a MenuStrip (Visual C#))

我想让Windows窗体应用程序使用带有三个选项的菜单栏来启动控制台应用程序。 控制台应用程序是Visual Studio中用C#构建的.exe文件,其中包含一些用于学校项目的基本代码。 控制台应用程序不需要返回任何值,只需运行并允许用户使用它。 这就是表单的样子: 菜单应用程序

我尝试在我的菜单项单击事件方法中使用Process.Start@("Path of file")导入System.Diagnostics.Process.Start命名空间以启动我的C#控制台应用程序,但尚未成功。 我得到一个“Win32Exception is unhandled:System.dll中发生未处理的类型'System.ComponentModel.Win32Exception'的异常。其他信息:系统找不到指定的文件”

以下是菜单项单击事件中的代码:

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void lesson13LabCToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start(@"\C:\Users\Sam\Documents\Visual Studio 2015\Projects\LabMenu\LabMenu\Lesson13LabC.exe"); } }

关于我做错什么的想法?

I want to have a Windows Form Application use a menustrip with three options to launch a console application. The console application is a .exe file built in C# in Visual Studio with some basic code for as school project. The console application does not need to return any values, it only needs to run and allow the user to use it. This is what the form will look like: Menu Application

I have tried importing the System.Diagnostics.Process.Start namespace with Process.Start@("Path of file") in my menu item click event method to launch my C# console application but have not been successful. I am getting a "Win32Exception was unhandled: An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll. Additional information: The system cannot find the file specified"

Here is the code in the menu item click event:

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void lesson13LabCToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start(@"\C:\Users\Sam\Documents\Visual Studio 2015\Projects\LabMenu\LabMenu\Lesson13LabC.exe"); } }

Any ideas on what I am doing wrong?

最满意答案

错误很明显The system cannot find the file specified 。 检查文件的路径。

还要删除路径中的起始\

The error is clear The system cannot find the file specified. Check the path of file.

Also remove the starting \ in the path

更多推荐

本文发布于:2023-08-04 01:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   应用程序   MenuStrip   Visual   Applications

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!