Reputation: 1
I have some issues displaying a second form after clicking a specific button in my first form. The question might sound silly, but I am a newbie to programming...
I have added a new Windows form into my project (Form2), but still, when I use
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Report()
{
InitializeComponent();
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 Report = new Form2();
Report.Show()
}
}
}
I get the following error
Error 1 The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?) d:\Projects C#\The Bizzy D\The Bizzy D\Form1.cs 661 13 The Bizzy D
What am I doing wrong then? Any ideas would be appreciated. Thanks!
Upvotes: 0
Views: 121
Reputation: 26209
If you Want To Open Form2 On Form1 Button Click Event.
Follow the Below Steps:
- Right Click on Project.
- Add->Windows Form...
- Enter the Form Name : Form2.cs
- Write the following Button Click Event Code in Form1.
private void btnShowForm2_Click(object sender, EventArgs e)
{
new Form2().Show();
}
Upvotes: 0
Reputation: 10238
You forgot a using directive as the error message states. The problem is, that even if you created this second form, the connection between the type name Form2
and the file it contains isn't clear to C#.
Upvotes: 1