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?
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.)
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.
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?
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?
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.
Try renaming Form1 before changing the Startup in the project properties.
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.
hello everyone, I have the following problem, it happens that I want to close an example application: Notepad, but the code only works for me if I have the form in the foreground if it is minized, do not close the application, I want to close the application no matter what window I am using , this is my code.
If e.KeyCode = Keys.Escape Then
Dim processesByName() As Process = Process.GetProcessesByName("Inventory")
Dim array() As Process = processesByName
ForEach process As Process In array
hello, I see your message I was a bit sick, it happens that the code I have works but as long as I don't have the form in the foreground it doesn't close the program that I want to close, to close the program I always have to have the form in the foreground and that's it I don't want
I tell you I have a program for online connection, it runs the MAME emulator online, 3 instances open, one the main menu, the second the KAILLERA and the third the game window already executed, then when you press the ESC key the game window will close but it remains it still activates the MAME main menu window but if I go to the main form and press the ESC key it completely closes the emulator
Last Visit: 31-Dec-99 19:00 Last Update: 29-Feb-24 23:10