Reputation: 256771
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.
Upvotes: 19
Views: 14358
Reputation: 9
You need to click on "Show All Files" Icon at the top of the Solution Explorer before renaming the form. If you do not then some support files do not get renamed.
Upvotes: 0
Reputation: 552
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
:
Check all the places you want it changed:
Upvotes: 5
Reputation: 1006
You may edit the designer file. Stay clear of the region labeled "Windows Form Designer generated code" and you will be fine.
Upvotes: 19