简体   繁体   English

在C#中按按钮时运行项目

[英]Run project when press button in C#

我有两个项目,一个是Windows窗体,程序集名称为“ project_1”,第二个项目为consol项目名称,为“ project_2”,我使用了多个启动项目来运行这两个程序并初始化了“ project_2”,我的问题是有没有办法使“当按下项目1中的按钮时,将运行project_2” ???

I have provided code for both the forms application and console application. 我已经为表单应用程序和控制台应用程序提供了代码。

Windows Forms application Windows窗体应用程序

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        AllocConsole();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        ConsoleApplication.Program.Main(new string[] {});
    }

    [DllImport("kernel32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool AllocConsole();
}

Had to add the DllImport to access the unmanaged code. 必须添加DllImport才能访问非托管代码。

Console appplicaion 控制台设备

public class Program
{
    public static void Main(string[] args)
    {
        using (var writer =
            new StreamWriter(@"C:\Users\Farttoos\Desktop\Nasser_Last\Crypto(AES)_Stego(text)_Final\Crypto_Stego\Dictionary.txt"))
        {
            Console.SetOut(writer);
            Console.Write("Hello World!");
            Act();
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM