Answered by:
Coping 1 project to another project.

Question
-
User-2081767517 posted
Hi all. I am currently new to coding and i have this group project with my teammates but we are currently having difficulty with trying to show form 2 when the button in form 1 is pressed. It shows an error called CS0118('Form2' is a namespace but used like a type). This is my code:
private void button1_Click(object sender, EventArgs e)
{
Form2 thankyou;
thankyou = new Form2();
thankyou.showDialog();
}Wednesday, January 27, 2021 9:30 AM
Answers
-
User409696431 posted
Your code looks like Windows Forms, not Web Forms. (https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.showdialog?view=net-5.0 ) If you are working on a Windows Forms project (an application that runs on a Windows PC), you are in the wrong forum, but that link shows you how to do what you are trying to do. If you are working on a Web Forms project (a website), which is what this forum is for, that code won't work. Please clarify which type of project you are working on.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 28, 2021 3:31 AM
All replies
-
User1120430333 posted
private void button1_Click(object sender, EventArgs e)
{
var thankyou = new Form2();
thankyou.showDialog();
}I can't see you project but try the above. If it works than find out what the usage of 'var' means in c#.
Wednesday, January 27, 2021 8:45 PM -
User-2081767517 posted
It did not work. Like it still have the same error.
Thursday, January 28, 2021 12:17 AM -
User409696431 posted
Your code looks like Windows Forms, not Web Forms. (https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.showdialog?view=net-5.0 ) If you are working on a Windows Forms project (an application that runs on a Windows PC), you are in the wrong forum, but that link shows you how to do what you are trying to do. If you are working on a Web Forms project (a website), which is what this forum is for, that code won't work. Please clarify which type of project you are working on.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 28, 2021 3:31 AM -
User-2081767517 posted
ohhhh. sorry. Thank you!
Monday, February 15, 2021 7:59 AM