Geekpedia Forums Logo

output text with windows forms

by Brian Ramming on Tuesday, September 11th - 7:59 PM



Hello,

I just came over from mainly programing console applications to giving windows forms and .NET a try. One major question I had was writing output to the screen. The classic example that is always done is the "Hello World" application. With a console app. a simple cout<<"Hello World"<<endl will output that to a console. I was wondering how would I code this using windows Forms and C#.  I know about the console.write method in C# but that goes back to console applications and I want to get it to work with windows Forms.

Thank you for your time and help.

Brian

The equivalent of a Hello World console application that shows output in the MS-DOS console is to show a dialog with the same message in a Windows Application upon form load or the click of a button. Here's how you show that message when the form loads (and thus the application starts):

If you're using Visual Studio, the first thing you should to is to create a Windows Application project. Then double click the form that was created for you by Visual Studio. You will get to its Load even that looks like this:

void Form1_Load(object sender, EventArgs e)
{
}

Inside it paste this code:

MessageBox.Show("Hello World!");

Now compile and run using F5.

Hey guys. Just wondering. When you run a windows application in visual studio you get an output window that shows the console output such as WriteLine. When i just run an executable version of the app (outside of visual studio) i dont get this.
Any idea how to show console output?
-Mark