Move Form to Namespace (VB 2005)

A

Armin Zingler

Hi all,

I have a Form called "Main":

Public Class Main

Private Sub Button1_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click

End Sub

End Class


Now I want to put the form into a namespace called "Forms". If I put the
lines "Namespace Forms" and "end namespace" before and after the code above,
I get an error at the "Handles" clause. Reason: The "Partial Class" in
Main.Designer.vb is still in the old Namespace. Consequently the class in
Main.vb is a different class not having any buttons anymore, therefore the
error.

Now I could manually also put the whole "Partial Class" into the "Forms"
namespace, but as the file is "designer generated" I can not touch it (or
take the risk that my lines will be overwritten).

So, how do I move a Form into a namespace in VB 2005? This was no problem in
VB 2003 because it was all one file.


Armin
 
T

Tom Shelton

Hi all,

I have a Form called "Main":

Public Class Main

Private Sub Button1_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click

End Sub

End Class


Now I want to put the form into a namespace called "Forms". If I put the
lines "Namespace Forms" and "end namespace" before and after the code above,
I get an error at the "Handles" clause. Reason: The "Partial Class" in
Main.Designer.vb is still in the old Namespace. Consequently the class in
Main.vb is a different class not having any buttons anymore, therefore the
error.

Now I could manually also put the whole "Partial Class" into the "Forms"
namespace, but as the file is "designer generated" I can not touch it (or
take the risk that my lines will be overwritten).

So, how do I move a Form into a namespace in VB 2005? This was no problem in
VB 2003 because it was all one file.


Armin

Just change it and make your default namespace the new namespace. You should
have a problem with it... At least, I haven't in c# :)
 
A

Armin Zingler

Tom Shelton said:
Just change it and make your default namespace the new namespace.
You should have a problem with it... At least, I haven't in c# :)

Uhm, sorry, but I don't understand. What should I change? The designer
generated file? Why should I have a problem with it? I don't want to change
the default namespace (you mean the root namespace of the project?), I only
want to put the Form in the Namespace.


Armin
 
P

Patrick Steele

Now I want to put the form into a namespace called "Forms". If I put the
lines "Namespace Forms" and "end namespace" before and after the code above,
I get an error at the "Handles" clause. Reason: The "Partial Class" in
Main.Designer.vb is still in the old Namespace. Consequently the class in
Main.vb is a different class not having any buttons anymore, therefore the
error.

Now I could manually also put the whole "Partial Class" into the "Forms"
namespace, but as the file is "designer generated" I can not touch it (or
take the risk that my lines will be overwritten).

I've done this before (in C#) and never had a problem with VS.NET
messing up my namespace declaration in the Main.Designer.cs file after
editing the form.
 
M

Michael D. Ober

You need to right click your solution and select view hidden files. Now you
can see and edit the designer files. The issue you are running up against
is that the VB IDE creates "default" namespaces.

Mike Ober.
 
T

Tom Shelton

Uhm, sorry, but I don't understand. What should I change? The designer
generated file?

Yes. Just change the namespace declaration in the designer file.
Why should I have a problem with it?

I meant you should not have a problem. It was a typo.
I don't want to change
the default namespace (you mean the root namespace of the project?), I only
want to put the Form in the Namespace.

I see, you already changed it and you are moving the form into it... Then just
change the designer file. It shouldn't cause any issues.
 
A

Armin Zingler

Tom Shelton said:
Yes. Just change the namespace declaration in the designer file.


I meant you should not have a problem. It was a typo.

Ah, I see.
I see, you already changed it and you are moving the form into it... Then
just
change the designer file. It shouldn't cause any issues.

Ok, I'll try.

Thanks Tom.


Armin
 
A

Armin Zingler

Patrick Steele said:
I've done this before (in C#) and never had a problem with VS.NET
messing up my namespace declaration in the Main.Designer.cs file
after editing the form.

Ok, seems to be save. I'll try it.

Thanks Patrick.


Armin
 

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

Top