Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

problems compiling first Windows application

BobLewistonBobLewiston Member Posts: 43
I tried to compile a Windows Forms Application in Visual C# 2008 Express with this source code from the CSharpSchool tutorial at Programmer's Heaven:[code]using System;
using System.Windows.Forms;
using System.Drawing;
namespace CSharpSchool
{
class HelloWinForm
{
static void Main ()
{
Application.Run (new MyWindow ());
}
}
class MyWindow : Form
{
public MyWindow () : base ()
{
this.Text = "My First Windows Application";
this.Size = new Size (300, 300);
Label lblGreeting = new Label ();
lblGreeting.Text = "Hello WinForm";
lblGreeting.Location = new Point (100, 100);
this.Controls.Add (lblGreeting);
}
}
}[/code]but I got these errors:

Error 1 Program 'C:Documents and SettingsBobLocal SettingsApplication DataTemporary ProjectsHelloWinFormobjReleaseHelloWinForm.exe' has more than one entry point defined: 'HelloWinForm.Test.Main()'. Compile with /main to specify the type that contains the entry point. C:Documents and SettingsBobLocal SettingsApplication DataTemporary ProjectsHelloWinFormForm1.cs 8 21 HelloWinForm

Error 2 Program 'C:Documents and SettingsBobLocal SettingsApplication DataTemporary ProjectsHelloWinFormobjReleaseHelloWinForm.exe' has more than one entry point defined: 'HelloWinForm.Program.Main()'. Compile with /main to specify the type that contains the entry point. C:Documents and SettingsBobLocal SettingsApplication DataTemporary ProjectsHelloWinFormProgram.cs 14 21 HelloWinForm

Error 3 'HelloWinForm.Form1.Dispose(bool)': no suitable method found to override C:Documents and SettingsBobLocal SettingsApplication DataTemporary ProjectsHelloWinFormForm1.Designer.cs 14 33 HelloWinForm

Feeding this into a search engine:

"visual c#" "Compile with /main"

yielded this link:

Compiler Error CS0017
Visual C# Reference: Errors and Warnings. Compiler Error CS0017 ... Compile with /main to specify the type that contains the entry point. ...
msdn.microsoft.com/en-us/library/t9k01y87.aspx

which said:

If you are using MS Visual Studio and do not want to delete the other Main() methods you can specify the class which you want as you Entry Point in Startup Object in the Project Properties under Application Tab (at least for VS2008 Express)

Going to:

Project | HelloWinForm Properties | Application | Startup Object

I discovered it wasn't set. Setting it to either HelloWinForm.Test or HelloWinForm.Program, the first two problems disappear, but not the third. I can't see how this code has more than one entry point, and I'm not at all clear on why the compiler requires these gyrations in Startup Object. None of these issues are mentioned by CSharpSchool, which claims the code I used will run as written. This is my first Windows app, and WOW! am I in the dark on this. What gives? Maybe I should just get a different tutorial. Any explanations of this or, failing that, any suggestions for which tutorial(s) I should use?

Comments

  • secutossecutos Member Posts: 10
    The reason why it says you have two Main() methods is because you actually do. One in the HelloWinForm class, and one in Program.cs, which is provided by default by your IDE, C# Express 2008 Edition. If you want to make a hello world form, just make a new "Windows Application" in your C# Express 2008 Edition, drag a Label control from the left toolbox and play around with the properties. I think it's much more fun than manually typing out the properties.
Sign In or Register to comment.