0

In c#, when you create a form, a set of three files are created that seem to be vital:

  • form1.cs
  • form1.resx
  • form1.designer.cs

I am required to add the form as a link to a file, so that the solution and source code are stored separately. I have moved these created files and added them as links as shown in this question:

Add File as a Link on Visual Studio - Debug vs Publish

But then the files are no longer linked together, so the GUI that has been created is lost (shows a blank form instead of what was added). I have tried forcing them to be linked together by editing the csproj as described in this answer. I added the DependentUpon tag to each of the resx and designer files:

  <Compile Include="Path\To\Form1.Designer.cs">
  <Link>Form1.Designer.cs</Link>
  <DependentUpon>Form1.cs</DependentUpon>
</Compile>

But this just crashes Visual Studio.

I know that you can manually link them, by dragging from the file explorer into visual studio under the Form1.cs listed in the solution explorer. This will work and the resx and designer will be under form1.cs (and the GUI shows correctly), but will copy the file to the project directory (as in it is not added as a link).

Is it possible to achieve this?

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175

2 Answers2

1

The key here is to only add the DependantUpon tag to the designer.cs file descriptors. Not to the .resx files.

  1. Move the files to the desired location.
  2. Add the form1.cs and form1.resx and form1.designer.cs files as a link to the project.
  3. Edit the .csproj file and add <DependentUpon>Form1.cs</DependentUpon> only to the designer file.

You will end up with the solution explorer showing the form1.resx file outside of the form1.cs file, but the GUI can still be visualized correctly and the solution will compile.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
-1

Add the windowform "as a link".

enter image description here

jiten
  • 5,128
  • 4
  • 44
  • 73
  • Yeah, you clearly didn't read the question. It didn't work like this. The GUI elements disappear and it wont build correctly anymore. – Fantastic Mr Fox Feb 08 '18 at 05:22
  • I have just added a form as a link. When I do changes in one form. it is reflecting to other place. – jiten Feb 08 '18 at 05:26
  • I have a pre-existing form, the form has GUI elements on it already. When i move the form to a new location and add it as a link, it wont show the gui elements because the designer file isnt linked correctly. Even if you link the designer file, it still wont work, because the `dependantupon` tag doesn't get set correctly. This is all outlined in the question. – Fantastic Mr Fox Feb 08 '18 at 05:30