Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.Write Not Working In Win Forms App

I created a VB.NET Windows Forms Application in Visual Studio 2008. When I run my program from the command-line, I get no output (only the next prompt).

What am I doing wrong?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Debug.Write("Foo")
    Debug.Flush()
    Console.WriteLine("foo")
    Console.Beep(800, 100) 'confirm this function is called'
    Me.Close()
End Sub

EDIT: Can a program have a form and a console?

EDIT2: Ho's answer works. However, the output appears on the next command-line prompt. Can a Winforms application tell the command-line to wait until it's finished instead of immediately returning?

like image 560
Steven Avatar asked Apr 14 '10 14:04

Steven


2 Answers

Tested similar code with a C# .NET Windows Form Application. Outputs and beeps nicely within Visual Studio but only beeps when run at the command line.

If I change the Output Type to Console Application under the Application tab for the Project properties, I get to use both the form and console :)

like image 109
anonymous Avatar answered Oct 20 '22 15:10

anonymous


You can run your app from the console using myApp.exe|MORE
This way the console will show Console.WriteLine() calls coming from the app and will wait until the app exits.
Please excuse my bad english.

like image 34
Ivan Ferrer Villa Avatar answered Oct 20 '22 16:10

Ivan Ferrer Villa