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;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 myform = new Form2();
myform.ShowDialog();
}
}
}
以下代码应该“启动”form2。它们位于同一个项目中,并具有相同的命名空间。我不明白。我已经尝试将.NET框架从版本4客户端更改为版本4。
还有其他想法吗?
答案 0 :(得分:3)
右键单击Form2,选择“resolve”并选择其中一个分辨率,或者将其移至WindowsFormsApplication3
命名空间。
答案 1 :(得分:3)
在我的情况下,我创建了form2
,但稍后重命名了。
我发现尽管表单的名称已更改,但类的名称仍保留为我最初创建它的名称。
例如:
1. 项目 - >添加Windows表单(Setup.cs
)
2. 文件 - >将Setup.cs另存为... (frmSetup.cs
)
3.添加代码:frmSetup SetupForm = new frmSetup();
但是,Setup类的实际名称并未随文件名更改,因此将我的代码更改为:
Setup SetupForm = new Setup();
所以我引用了类名而不是文件名解决了我的问题。
答案 2 :(得分:0)
你可以用两种方式解决这个问题:
答案 3 :(得分:-1)
两个表单应该具有相同的命名空间