i have a form that is currently in the wrong namespace:
MyForm.cs:
namespace DirtyHowdoyoudo
{
public MyForm()
{
...
MyForm.Designer.cs:
namespace DirtyHowdoyoudo
{
partial class MainForm
{
The form should be in the namespace Bajingo
. What is the proper way to change the namespace of a form?
Note: Editing MyForm.cs
to use the new namespace:
MyForm.cs:
namespace Bajingo
{
public MyForm()
{
...
causes the designer to break. i could edit the MyForm.Designer.cs
code file manually:
MyForm.Designer.cs:
namespace Bajingo
{
partial class MainForm
{
But i am told by Visual Studio (and SO users - who suggest "use refactor") not to manually edit the designer file.
Obligatory filler material:
i checked the properties window for the form, and there is no Namespace
property:
i tried to just rename it, and let the Visual Studio refactor kick in:
Except that Visual Studio wants to rename the namespace everywhere, in everything. i just want this one form.
You can change the default namespace: -> Project -> XXX Properties... Instead of Find/Replace, you can also right click the namespace in code and Refactor->Rename.
Assigned Tags. you can't rename a namespace. if it's only one object you can copy and rename it.
The root namespace is also the default namespace for C# programs.
Visual Studio assigns your project name as the default root namespace for all code in your project. For example, if your project is named Payroll , its programming elements belong to namespace Payroll . If you declare Namespace funding , the full name of that namespace is Payroll. funding .
You may edit the designer file. Stay clear of the region labeled "Windows Form Designer generated code" and you will be fine.
As of VS 2017, you can highlight the namespace you want to rename, right click over it, click Rename
, then change it to the new namespace name, then click on Apply
in the dialog that should have appeared when you clicked Rename
.
1) Highlight the namespace you want to rename and right click, then click Rename
:
Type the new namespace name, make sure Preview Changes
is ticked and click Apply
:
2)
Check all the places you want it changed:
3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With