Forms Namespace

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How to I change the namespace for a form in vs 2005? Do I add "
"Namespace/End Namespace" to both of the partial files? Or is there an easy
way to keep them both sync'd?
 
Hi Dick,

Use the Class View from the View menu (CTRL W, C). Right click your namespace and rename...
 
Dick said:
How to I change the namespace for a form in vs 2005? Do I add "
"Namespace/End Namespace" to both of the partial files? Or is there an easy
way to keep them both sync'd?

Follow what Morten said and that will work if things are already setup.
However, technically the easiest way is to create them correctly in
the first place. I don't know if this is the case, and may not be.

A lot of people though don't understand that the directory structure in
your project, predetermines the Namespace though. This doesn't sound
like the case but I'll state it in case someone else searches for it.

I typically name my projects based on namespaces. IE:

DotNetPimps.UI.WinForm.Controls may be a namespace and it is also a project.

If I add a folder in this project called DataGrids for example, and then
I add a new user control called ContactGrid to the folder DataGrids, the
namespace automatically picks up as:

DotNetPimps.UI.WinForm.Controls.DataGrids

in the file ContactGrid.cs.

If you setup your projects correctly to begin with, you don't even think
about Namespaces because you've thought about them before coding which
is a good practice.

My $.02.

-Keith
 
Thanks for your response but (CTRL SHIFT C) is the (default) shortcut to the
class view not (CTRL W, C). And right clicking a namespace does not present
any option to rename it. Nor does F2 or clicking twice, etc.

In any case, I don't want to rename a namespace, I want to change the
namespace of a specific class (well, lots of classes really). In 2003 this
was easy because one class = one file so it was simply a case of adding
Namespace/End Namespace to the single file. But in 2005 we have partial files
and thus there are multiple updates and the issue of synchronisation. So I
thought "there must be an easy way". But I can't find it!
 
Thanks for your reply. However, (a) I tried to follow what Morten said but
couldn't - see my other post - and (b) while I like and very much agree with
you views on folder structure mirroring namespaces I'm a little confussed by
what you say because I've never seen this automatic namespace maintenance
happening. In all our projects we keep the folder structure and namespaces
hierarchy in sync but I've never seen any automatic setting of/changes to
namespaces. Is this a c# thing only - we're all vb - or do you have to be
careful about project naming and/or do you need to get your root namespace
and project name in sync. I've had a quick play around but couldn't get
anything going!
 
Hi Richard,

I am not sure what's wrong with your VS2005 IDE, I can just open the class
view and use the Rename context menu option to change the class namespace.
Have you tried this on other machines?

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
All our machines are the same - they're all built from the same Ghost image.
We rebuild from our Ghosts regularly (at least once a week) - so I'm certain
my installation is the same as it was the day we installed VS2005.

Just to be clear, this is what I think you want me to do...

1. Fire up VS2005 and create a new project (WindowsApplication/VisualBasic).
This creates the expteced project with a single class - "Form1".
2. Open the Class View window (View>Class View). Expand the
"WindowsApplication" project node and the "WindowsApplication" namespace node.
3. Right-Click the "Form1" class node and select the "change namespace"
option. But the only options I have are: ViewClassDiagram, GoToDefinition,
BrowseToDefinition, FindAllReferences, FilterByType, CreateInstance,
InvokeStaticMethod, Copy, SortAlphabetically, SortByObjectType,
SortByObjectAccess and GroupByObjectType.

So, am I doing something wrong, or is there something about my installation?
 
I don't know if there are any easy way to change namespaces other than already known global namespaces. Right clicking on a namespace and selecting rename will rename the namespaces of all classes etc using that namespace, right clicking on a class and selecting rename will just rename that class, not the namespace.

I'm afraid you need to do it manually.

All our machines are the same - they're all built from the same Ghost image.
We rebuild from our Ghosts regularly (at least once a week) - so I'm certain
my installation is the same as it was the day we installed VS2005.

Just to be clear, this is what I think you want me to do...

1. Fire up VS2005 and create a new project (WindowsApplication/VisualBasic).
This creates the expteced project with a single class - "Form1".
2. Open the Class View window (View>Class View). Expand the
"WindowsApplication" project node and the "WindowsApplication" namespace node.
3. Right-Click the "Form1" class node and select the "change namespace"
option. But the only options I have are: ViewClassDiagram, GoToDefinition,
BrowseToDefinition, FindAllReferences, FilterByType, CreateInstance,
InvokeStaticMethod, Copy, SortAlphabetically, SortByObjectType,
SortByObjectAccess and GroupByObjectType.

So, am I doing something wrong, or is there something about my installation?

"Jeffrey Tan[MSFT]" said:
Hi Richard,

I am not sure what's wrong with your VS2005 IDE, I can just open the class
view and use the Rename context menu option to change the class namespace.
Have you tried this on other machines?

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Richard,

Thanks for your feedback.

With your further feedback, I understand your requirement much better now.
You just want to change a single class' namespace to a new one, not rename
an existed namespace.

Currently, VS2005 IDE did not implement such function, just as "Morten
Wennevik" said; we can only rename an existed namespace. However, I think
your requirement makes sense from productivity perspective, so I suggest
you feedback this requirement in the link below:
http://lab.msdn.microsoft.com/ProductFeedback/

Our product team will get your feedback and follow up with you in this
link. They may consider your suggestion and add it in next release.

Last note: it seems that this issue is more related with VS ID, not winform
specific, so I suggest you post such issue in microsoft.public.vsnet.ide
newsgroup. You will get more useful community responses there. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top