Changing the start up form

T

Toby

I am a little new as you can tell by this post.

This is my first c# window app and I made all my forms and now trying to go
back and change the start up form and it is giving me errors when I change
the form name that is below. And help on this would be nice..



Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmIMOptions());
 
P

Peter Duniho

Toby said:
I am a little new as you can tell by this post.

This is my first c# window app and I made all my forms and now trying to
go back and change the start up form and it is giving me errors when I
change the form name that is below. And help on this would be nice..

If you don't tell us what errors you're getting, there's no way for anyone
to suggest anything about how to fix them.
 
D

Dave Sexton

Hi Toby,

What is the exact error message?

Can you confirm that frmIMOptions is a class in your project that derives from
Form?

Example:

class frmIMOptions : Form
{
}

(probably located in a file named, "frmIMOptions.cs")

Can you confirm that either:

A. The namespace of the class that contains your Main method is the same as
the namespace of the frmIMOptions class

B. Otherwise, the compiler may require a "using [namespace]" statement in the
file that contains your Main method to scope frmIMOptions
 
V

V

Hmm... do you have a keyword public in front of the class declaration
for whichever form you are changing it to?

Or you can try moving the Main method to the form that you want to load
at startup and change the name of the form in Application.Run after
moving it.

Regards,
Vaibhav
 
T

Toby

Error 1 The type or namespace name 'frmIMAddOptions' could not be found (are
you missing a using directive or an assembly reference?) C:\ \ \ \My
Documents\Visual Studio 2005\Projects\Options Tool\Options Tool\Program.cs
17 33 Options Tool

Sorry about that
 
T

Toby

The static void Main() is in the Program.cs.
That is is where VS put it. Can I move that?
 
T

Toby

Ok I moved it from the program.cs to the form I wanted as a start up and
that works. I thank you all for the help. I am sure I will be back soon with
more questions.
 
D

Dave Sexton

Hi Toby,

I don't recommend moving the Main method from the Program file.

Instead, include the frmIMOptions's namespace into the Main method's scope.
You can do this quite easily in VS 2005:

1. Place the cursor over "frmIMOptions" in the following line:

A red box should appear under the "s".

2. Hover the mouse over the red box
3. Click the drop-down array that appears
4. Select the "using" item that has the appropriate namespace for your class

To find out the namespace that frmIMOptions is in, open the file that contains
the frmIMOptions class in code view (probably "frmIMOptions.cs") and find the
namespace:

namespace ThisIsYourProject.AndThisIsASubNamespace
{
public class frmIMOptions : Form
{
...
}
}

Let us know if you don't see the red box, the drop-down or the appropriate
namespace in the list
 
D

Dave Sexton

Hi Toby,

If you look at the top of the file that contains the Main method you'll now
see a "using" statement that provides the namespace of the frmIMOptions Form.
This statement tells the compiler where to look to resolve unqualified
references to the "frmIMOptions" token.

You could have added this yourself, manually, although it's usually quicker to
just allow VS to do it for you (this feature is new to VS 2005).

HTH
 
T

Toby

Dave,
what would be a good book to get to really get started with c#? I have
been programming in VB6 for a while now so some of the concepts are
formulary but the syntax is killing me.


Toby
 
D

Dave Sexton

Hi Toby,

I'm sorry but I don't know of any good books to recommend. Hopefully someone
else will fill in the blanks there :)

There are, of course, a lot of refences on the web that could be an enormous
help to you. To name a few:

"C# Language Reference"
http://msdn2.microsoft.com/en-us/library/618ayhy6(VS.80).aspx

"C# Programming Guide"
http://msdn2.microsoft.com/en-us/library/67ef8sbd(VS.80).aspx

"Writing Applications with C#"
http://msdn2.microsoft.com/en-us/library/aezdt881(VS.80).aspx

Look at the TOC and you'll see many more topics that may interest you. There
are many references other than MSDN, of course, but I've only included these
because they contain enough information to keep you busy for at least a few
hours ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Main() questions 3
A simple question about show 2
Forms Flow 7
My timer doesn't work 1
using the show command 1
Error Creating Window Handle 5
Close the Program 1
Not showing a form when an application runs 2

Top