problems compiling first Windows application

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 80
Reputation: BobLewiston is an unknown quantity at this point 
Solved Threads: 0
BobLewiston BobLewiston is offline Offline
Junior Poster in Training

problems compiling first Windows application

 
0
  #1
Feb 11th, 2009
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:
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. namespace CSharpSchool
  5. {
  6. class HelloWinForm
  7. {
  8. static void Main ()
  9. {
  10. Application.Run (new MyWindow ());
  11. }
  12. }
  13. class MyWindow : Form
  14. {
  15. public MyWindow () : base ()
  16. {
  17. this.Text = "My First Windows Application";
  18. this.Size = new Size (300, 300);
  19. Label lblGreeting = new Label ();
  20. lblGreeting.Text = "Hello WinForm";
  21. lblGreeting.Location = new Point (100, 100);
  22. this.Controls.Add (lblGreeting);
  23. }
  24. }
  25. }
but I got these errors:

Error 1 Program 'C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\obj\Release\HelloWinForm.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 Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Form1.cs 8 21 HelloWinForm

Error 2 Program 'C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\obj\Release\HelloWinForm.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 Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Program.cs 14 21 HelloWinForm

Error 3 'HelloWinForm.Form1.Dispose(bool)': no suitable method found to override C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Form1.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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 58
Reputation: vckicks is an unknown quantity at this point 
Solved Threads: 9
vckicks vckicks is offline Offline
Junior Poster in Training

Re: problems compiling first Windows application

 
0
  #2
Feb 12th, 2009
Just some quick thoughts, if you are using .NET Framework 2.0 or up then you have the notion of partial classes, which means the code for the Form can be in several different files.

The code you posted seems to be designed to be the only code in the Form, so you could try to start a new project and on a new Form just copy this section:

  1. public MyWindow () : base ()
  2. {
  3. this.Text = "My First Windows Application";
  4. this.Size = new Size (300, 300);
  5. Label lblGreeting = new Label ();
  6. lblGreeting.Text = "Hello WinForm";
  7. lblGreeting.Location = new Point (100, 100);
  8. this.Controls.Add (lblGreeting);
  9. }

Just make sure "MyWindow" matches the name of the new Form and you can take off ": base()".

Hope that helps
Visual C# Kicks - Free C# code resources and articles.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,955
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 283
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: problems compiling first Windows application

 
0
  #3
Feb 12th, 2009
Start with New project. Choose Empty project, name it CSharpSchool. Choose Add Item and select class. Now type in your code.
Last edited by ddanbe; Feb 12th, 2009 at 5:37 am.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: problems compiling first Windows application

 
0
  #4
Feb 12th, 2009
=======
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?
=======
First, No, you do not need to set the Startup Object for this project.
Second, looks like a very old tutorial, I suggest getting a book so you are familiar with how VS structures a program.

To create your hello world project, let the IDE do the work for you.
Create a new Win Form project, drag a label named lblGreeting onto the form.
Now either setup the properties of the form for its Text and Size, and the Text for the label and just run it, OR (the hard way) in the constructor (the only method created for your new form) add the code under the existing InitializeComponent(); line.
  1. public Form1()
  2. {
  3. InitializeComponent();
  4. this.Text = "My First Windows Application";
  5. this.Size = new Size(300, 300);
  6. Label lblGreeting = new Label();
  7. lblGreeting.Text = "Hello WinForm";
  8. lblGreeting.Location = new Point(100, 100);
  9. this.Controls.Add(lblGreeting);
  10.  
  11. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC