窗体和控制台应用程序 [英] window form and console application

查看:108
本文介绍了窗体和控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我有窗口表单应用程序,我想同时运行窗口窗体和控制台(作为bat文件)。

I have window form application which I would like to run both window form and console (as bat file).

所以,如果参数传递我希望作为控制台运行也使用console.writeline写入控制台 

So, If argument is passed I want to run as console also write to console using console.writeline 

并且如果参数未通过则以窗口形式运行。

and If argument is not pass then run as window form.




推荐答案

我假设您有不同的类,一个用于运行表单和一个用于运行控制台。如果没有,你需要改变一下才能有两个类。

I assume that you have different classes, one for running a Form and one for running a Console. If not, you'll need to change things around to have two classes.

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Form1 f1 = new Form1();
            Application.Run(f1);
        }
        else
        {
            // just an example of how to get it going
            MyConsoleClass myConsole = new MyConsoleClass();
            while (true)
            {
                Console.WriteLine("Starting Console ...");
                myConsole.DoStuff(); // or whatever you're going to do here
                Console.ReadLine();
            }
        }
    }
}





这篇关于窗体和控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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