Jump to content
  • Advertisement
Sign in to follow this  
Kryptus

[.net] .NET Windows Form & Console?

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

<Programming Language=C# Version=2005> I have a simple network server with a Windows form for managing client user names. I have a textbox used for a console in another window. I was wondering, is there any way I can replace that window with a command line window? Or can a project ONLY be WINDOWS or CONSOLE?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Kryptus
<Programming Language=C# Version=2005>

I have a simple network server with a Windows form for managing client user names. I have a textbox used for a console in another window. I was wondering, is there any way I can replace that window with a command line window? Or can a project ONLY be WINDOWS or CONSOLE?

The distinction between "console" and "form" .NET applications is nil, save in their presentation. You don't have load the System.Windows.Forms and related assemblies to run a purely console application (unless you reference and use them for some reason), but that's about it. If you want to read or write from the console, use the Read/Write()/ReadLine()/WriteLine() methods of the Console class.

Share this post


Link to post
Share on other sites
you should create the project initially as a console project. From the console, you will be able to do normal console I/O as kSquared described, as well as be able to create and display forms. Example:

using System;
using System.Windows.Forms;

namespace ConsoleApp{
class ConsoleAppBegin{
[STAThread]
public static void Main(string[] args){
Console.WriteLine("What's your input?");
string input = Console.ReadLine();
Console.WriteLine("you typed in: {0}", input);
Form f = new Form("Title: "+input);
Application.Run(f); //this will display the window and block until the window is closed.
Form g = new Form("some other title");
g.Visible = true; //this will not block, code in this method will continue to execute.
//anything else you want to do
}
}
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!