Results 1 to 4 of 4

Thread: Show console window instead of GUI

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Show console window instead of GUI

    I have this program that is a GUI program in C#.
    I am working on implementing a way to make it do what it does but automatically via the console.

    For example I can give the args "-console -i "Input" -o "Output"
    and then it writes in the console window and never shows the GUI.

    I know how to hide the GUI, but I don't know how to make it write to the console window? Just writing Console.WriteLine("Hello") doesn't work, it doesn't write that line to the console window. (via CMD.exe)

    Any1 that has a clue on what I need to do?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Show console window instead of GUI

    You may have to attach to the console using the Win32 method AttachConsole. Take a look at this example.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Show console window instead of GUI

    Thanks for that link. I tried it and it kinda worked, but it was a little to dirty method for me. I will make some custom solution instead. Thx again!

  4. #4
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Show console window instead of GUI

    if you dont mind the console window being opened, then change your project settings to be a console application (after you created your winforms project)

    any input/output from then will be displayed on the console - your winforms app/forms will also be shown.

    you may need to redirect your inputs/outputs from your winforms app to the console. again - many solutions but depends what your requirements are

    I also believe you can change the program.cs on the Main() method and prevent it from running the form itself and just use that area to implement your logic for inputs etc...
    Last edited by Techno; Jun 7th, 2011 at 06:32 AM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width