Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Simple question: why does Visual Studio "freak out" when changing Form1 name to something different

Simple question: why does Visual Studio "freak out" when changing Form1 name to something different

Scheduled Pinned Locked Moved Visual Basic
questioncsharpvisual-studiohelp
13 Posts 5 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C CHill60

    How are you "changing the name" - might sound like a silly question but you'd be surprised at some of the things I've seen Edit: And when - as in "immediately" or have you already written code that refers to it?

    L Offline
    L Offline
    lewist57
    wrote on last edited by
    #4

    Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?

    D L S 3 Replies Last reply
    0
    • L lewist57

      Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #5

      Nope. You do not use the Properties window to change the name of a form. Usually, you either click on the file with the form name and hit F2 to change the name of the file (which VS will happily change the name of the class for you to go along with it), or you click on the class name and hit F2 to rename the class (and all of it's other locations.)

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      L 1 Reply Last reply
      0
      • L lewist57

        Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #6

        I gave you the answer yesterday; did you try it?

        L 1 Reply Last reply
        0
        • L Lost User

          I gave you the answer yesterday; did you try it?

          L Offline
          L Offline
          lewist57
          wrote on last edited by
          #7

          Yes I did. Following the same steps, create a desktop VB windows form .NET 6 project, let the project come up with the standard Form1, then right click on Form1.vb in Solution Explorer, rename as frmMain.vb results in the same error message when you build it after the name change.

          L 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Nope. You do not use the Properties window to change the name of a form. Usually, you either click on the file with the form name and hit F2 to change the name of the file (which VS will happily change the name of the class for you to go along with it), or you click on the class name and hit F2 to rename the class (and all of it's other locations.)

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            L Offline
            L Offline
            lewist57
            wrote on last edited by
            #8

            Unfortunately, when I create a new project, let Form1 come up and then click on Form1.vb under Solution Explorer, click on Form1.vb, press F2, rename Form1 to frmMain, and then build, results in exactly the same build error.

            D 1 Reply Last reply
            0
            • L lewist57

              Unfortunately, when I create a new project, let Form1 come up and then click on Form1.vb under Solution Explorer, click on Form1.vb, press F2, rename Form1 to frmMain, and then build, results in exactly the same build error.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #9

              Well, something's going on that isn't normal. You can try to get around it by double-clicking "My Project" in Solution Explorer, click the Application tab, then find the "Startup object" dropdown. Click on that and find the name of your startup form and click it, then recompile. Are there any updates to Visual Studio and Windows that haven't been installed yet?

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              L 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Well, something's going on that isn't normal. You can try to get around it by double-clicking "My Project" in Solution Explorer, click the Application tab, then find the "Startup object" dropdown. Click on that and find the name of your startup form and click it, then recompile. Are there any updates to Visual Studio and Windows that haven't been installed yet?

                Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                Dave Kreskowiak

                L Offline
                L Offline
                lewist57
                wrote on last edited by
                #10

                "Well, something's going on that isn't normal." and hence the title of the post. Going to the application tab and selecting Form1 as the startup object, compiling, and then changing the form name in Solution Explorer allowed compilation without an error. However, I will note that after changing the form name from Form1 to frmMain as above, in the application tab/startup object, it is still "Form1" and not "frmMain". And while the form name in Solution Explorer is "frmMain", when you click on the form and look at Properties, it is still "Form1" My Win10 pc and VS are both up to date. Now here is where it gets even more interesting. Once again start a new project, VB/windows form/desktop/,NET 6, let the solution come up with Form1. Go to Project, Add form, and add a new form. At this time you can call it "frmMain" when it is added. Then go to Solution Explorer, select Form1 and delete it. So at this point, Form1 is gone, and only frmMain remains. Go to application tab/startup and select frmMain as the startup object. Build the solution and then you get: Error BC30456 'Form1' is not a member of 'test6'. Now VS is throwing errors on a "form" that has been deleted from the solution. So I know there are work arounds, but the (somewhat rhetorical) question is: why doesn't VS automatically update all references in the solution when a form's name is changed/deleted?

                D 1 Reply Last reply
                0
                • L lewist57

                  "Well, something's going on that isn't normal." and hence the title of the post. Going to the application tab and selecting Form1 as the startup object, compiling, and then changing the form name in Solution Explorer allowed compilation without an error. However, I will note that after changing the form name from Form1 to frmMain as above, in the application tab/startup object, it is still "Form1" and not "frmMain". And while the form name in Solution Explorer is "frmMain", when you click on the form and look at Properties, it is still "Form1" My Win10 pc and VS are both up to date. Now here is where it gets even more interesting. Once again start a new project, VB/windows form/desktop/,NET 6, let the solution come up with Form1. Go to Project, Add form, and add a new form. At this time you can call it "frmMain" when it is added. Then go to Solution Explorer, select Form1 and delete it. So at this point, Form1 is gone, and only frmMain remains. Go to application tab/startup and select frmMain as the startup object. Build the solution and then you get: Error BC30456 'Form1' is not a member of 'test6'. Now VS is throwing errors on a "form" that has been deleted from the solution. So I know there are work arounds, but the (somewhat rhetorical) question is: why doesn't VS automatically update all references in the solution when a form's name is changed/deleted?

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #11

                  Something is broken. I'd try uninstall VS and .NET 6 and reinstalling.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  1 Reply Last reply
                  0
                  • L lewist57

                    Yes I did. Following the same steps, create a desktop VB windows form .NET 6 project, let the project come up with the standard Form1, then right click on Form1.vb in Solution Explorer, rename as frmMain.vb results in the same error message when you build it after the name change.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #12

                    I have used that method on numerous occasions but never had a problem. I suggest you report it to Microsoft.

                    1 Reply Last reply
                    0
                    • L lewist57

                      Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?

                      S Offline
                      S Offline
                      Slow Eddie
                      wrote on last edited by
                      #13

                      Try renaming Form1 before changing the Startup in the project properties. OR------------------------------ I have also added a form under the form name I wanted (Like Title), again doing this before changing the Startup in the project properties, Save the project exit VS, open VS and load the project. When you go back to Project the drop-down should show the form you added. Select it, return to Solution Explorer and then delete Form1 properties or at least Exclude it from the project. Both of these have worked for me.

                      ed

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups