469,953 Members | 1,916 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,953 developers. It's quick & easy.

Move Form to Namespace (VB 2005)

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

Feb 11 '07 #1
7 2805
On 2007-02-11, Armin Zingler <az*******@freenet.dewrote:
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# :)

--
Tom Shelton
Feb 11 '07 #2
"Tom Shelton" <to*********@comcastXXXXXXX.netschrieb
On 2007-02-11, Armin Zingler <az*******@freenet.dewrote:
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# :)
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

Feb 11 '07 #3
In article <Oy**************@TK2MSFTNGP05.phx.gbl>, az*******@freenet.de
says...
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.

--
Patrick Steele
http://weblogs.asp.net/psteele
Feb 12 '07 #4
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.

"Patrick Steele" <pa*****@mvps.orgwrote in message
news:MP************************@msnews.microsoft.c om...
In article <Oy**************@TK2MSFTNGP05.phx.gbl>, az*******@freenet.de
says...
>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.

--
Patrick Steele
http://weblogs.asp.net/psteele


Feb 12 '07 #5
On 2007-02-11, Armin Zingler <az*******@freenet.dewrote:
"Tom Shelton" <to*********@comcastXXXXXXX.netschrieb
>On 2007-02-11, Armin Zingler <az*******@freenet.dewrote:
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# :)

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.

--
Tom Shelton
Feb 12 '07 #6
"Tom Shelton" <to*********@comcastXXXXXXX.netschrieb
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?

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.
Ah, I see.
>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.
Ok, I'll try.

Thanks Tom.
Armin

Feb 12 '07 #7
"Patrick Steele" <pa*****@mvps.orgschrieb
In article <Oy**************@TK2MSFTNGP05.phx.gbl>,
az*******@freenet.de says...
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.
Ok, seems to be save. I'll try it.

Thanks Patrick.
Armin
Feb 12 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Sumit Gupta | last post: by
6 posts views Thread by =?Utf-8?B?Unlhbg==?= | last post: by
3 posts views Thread by =?Utf-8?B?Umlja1NlYW4=?= | last post: by
reply views Thread by Hillbilly | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.