How do I create a C# app that decides itself whether to show as a console or windowed app?

前端 未结 11 803
广开言路
广开言路 2020-11-28 21:10

Is there a way to launch a C# application with the following features?

  1. It determines by command-line parameters whether it is a windowed or console app
11条回答
  •  甜味超标
    2020-11-28 21:10

    NOTE: I haven't tested this, but I believe it would work...

    You could do this:

    Make your app a windows forms application. If you get a request for console, don't show your main form. Instead, use platform invoke to call into the Console Functions in the Windows API and allocate a console on the fly.

    (Alternatively, use the API to hide the console in a console app, but you'd probably see the console "flicker" as it was created in this case...)

提交回复
热议问题