locked
Where to find Auto-Generated Code for C# Windows Forms

    Question

  • Hi all,

    I'm trying to find the auto-generated code that specifically assigns the properties of my chosen form component in the IDE. Everyone says that I should be able to see it in Solution Explorer under the node by the name of my form component.

    i.e. if i were to start a C# forms project with the name BasicForm, choose a form component like a button, place it in the designer on the form window, the CS file should show up in the BasicForm node with the name BasicForm.Designer.cs. I do not have such a file and I've expanded and clicked on every tree item. Is it named something else? Is it no longer accessible in 2008?

    thanks very much,

    Derek

    using Microsoft Visual Studio 2008
    Thursday, November 20, 2008 4:46 AM

All replies

  • Actually it will show up with the name Form1, unless you change the form name. The project name would be BasicForm. And yes, it would be Form1.Designer.cs


    Ron Whittle - If the post is helpful or answers your question, please mark it as such.
    Thursday, November 20, 2008 6:00 AM
  • ... make sure that Solution Explorer is set to display all files, although in VB I do not think that is needed.  Check the buttons at the top of the SE window.

    Rudedog   =|^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Saturday, November 22, 2008 12:37 PM
  • No, the files are still accessible in VS2008. There are a couple of things you can try. The easiest would be to go to your normal code file (MyForm.cs) find or create a reference to some gui element. Right click on that reference and in the resulting popup menu select "Find All References", every line where that object is referenced in MyForm.Designer.cs will show up in the Find Symbol Results window. You can then just double-click a line and it will open the file for you.

    Alternately, look in your file system using Explorer and make sure you have some file there that ends with *.designer.cs.

    Note the full name and return to VS IDE and look for it. As you noted if your form is named MyForm it will have a + next to it and opening it up should reveal all the dependent files including the MyForm.Designer.cs and MyForm.resx.  You won't need to use the "Show All Files" icon at the top of the Solution explorer because the designer files aren't hidden by default. 

    All this is defined in the .csproj file. If you still can't see it open up the .csproj file with a text editor and do a find for "designer.cs"
    You should see something like
      <ItemGroup>
        <Compile Include="MyForm.cs">
          <SubType>Form</SubType>
        </Compile>
        <Compile Include="MyForm.Designer.cs">
          <DependentUpon>MyForm.cs</DependentUpon>
        </Compile> ...




    Wednesday, November 26, 2008 9:45 PM
  • Tod_ said:

    No, the files are still accessible in VS2008. There are a couple of things you can try. The easiest would be to go to your normal code file (MyForm.cs) find or create a reference to some gui element. Right click on that reference and in the resulting popup menu select "Find All References", every line where that object is referenced in MyForm.Designer.cs will show up in the Find Symbol Results window. You can then just double-click a line and it will open the file for you.


    Alternately, look in your file system using Explorer and make sure you have some file there that ends with *.designer.cs.

    Note the full name and return to VS IDE and look for it. As you noted if your form is named MyForm it will have a + next to it and opening it up should reveal all the dependent files including the MyForm.Designer.cs and MyForm.resx.  You won't need to use the "Show All Files" icon at the top of the Solution explorer because the designer files aren't hidden by default. 

    All this is defined in the .csproj file. If you still can't see it open up the .csproj file with a text editor and do a find for "designer.cs"
    You should see something like
      <ItemGroup>
        <Compile Include="MyForm.cs">
          <SubType>Form</SubType>
        </Compile>
        <Compile Include="MyForm.Designer.cs">
          <DependentUpon>MyForm.cs</DependentUpon>
        </Compile> ...






    Designer files are hidden by default to as a means to people from editing them thereby corrupting their forms or other classes and objects that have auto-generated code.

    Rudedog   =|^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Wednesday, November 26, 2008 9:55 PM