open form onClick

PaulC

New member
Joined
Aug 18, 2023
Messages
1
Programming Experience
Beginner
I created a form and added some buttons. when I click the button labeled "RESIDENTS".
I want to open that form. I started this by inserting another form which is currently labeled Form2 but I changed the property under Design to "residents".
I double clicked the "residents" button in Form1 and inserted this code
C#:
 private void residentsBtn_Click(object sender, EventArgs e)
        {
            var residents = new Form2();
            residents.Show();
        }
the error says, "type or Namespace could not be found
 
You can't use the same name for the Button than for the Form name. Try:

var form = new Form2();
form.Show();
 
You can name variables anything that is a legal C# identifier. The error the OP is encountering is not related to the variable name.
 
Zip up your project and attach it to your post. Do not include the bin or obj folders in the zip. This could be one of multiple things and an experienced dev will be able to see it quickly by looking at the code, but there isn't enough info in your question to answer it

Do please call Form2 "ResidentsForm"; name all your variables and classes sensibly. No one wants to debug code that is obfuscated by poor choice of names
 

Latest posts

Back
Top Bottom