|
-
May 5th, 2012, 06:39 PM
#1
Changing GUI to Console
Hey everyone
I'm sort of a newbie with C# and I have downloaded a server-sided game source that uses GUI's. Personally I don't think GUI's are suitable at all for a game server so I wanted to change that to a Console instead.
So here is my problem. To run the server, you make a shortcut that opens the GUI with a configuration file. I tried changing this following code.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace ConsoleApplication1 {
static class Program {
public static frmMain MainForm { get; set; }
public static string IMGFilename { get; set; }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {
if (args.Length != 1) {
MessageBox.Show("Invalid argument length.");
}
else {
IMGFilename = args[0];
try {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(MainForm = new frmMain());
//Timer.Stop();
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
MainForm.Close();
Application.Exit();
}
}
}
}
}
I removed everything here and changed it to this, to test and see if it would work.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Derp");
Console.Read();
}
}
}
When I double click on the compiled executable, nothing will open or anything.
if anyone would like to provide assistance over either PM's or MSN it would be greatly appreciated!
Thanks everyone!
-
May 5th, 2012, 11:02 PM
#2
Re: Changing GUI to Console
What happens if you open a command line window and run it from there?
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
May 5th, 2012, 11:52 PM
#3
Re: Changing GUI to Console
 Originally Posted by BioPhysEngr
What happens if you open a command line window and run it from there?
It still will not run. I get a message saying "Program1.exe" has stopped working.
-
May 6th, 2012, 12:23 AM
#4
Re: Changing GUI to Console
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
May 6th, 2012, 01:43 AM
#5
Re: Changing GUI to Console
 Originally Posted by BioPhysEngr
Thank you! will try tommorow!
-
May 6th, 2012, 08:14 AM
#6
Re: Changing GUI to Console
Since that link is for C++, this is how you do it in C#:
Open project properties, Application tab (the first one), and set Output Type to "Console Application" from the dropdown.
Note, however, that there's more work to be done. In the original code, the line "Application.Run(MainForm = new frmMain())" starts a windows message loop, upon which all windowed applications are based. This is the underlying functionality which results, on the surface, in various events being raised (such as Load, Click, MouseMove, MouseDown, Paint, etc.). If the original app logic (or some of it) was based on handling WinForms events, then you have to recreate that functionality, since, in a console app, those events simply don't exist. But, since it's a server-side app, maybe the transition won't require too much work.
-
May 6th, 2012, 12:13 PM
#7
Re: Changing GUI to Console
Thanks, Cthulhu! Should have read my link better first... :-)
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|