![](/img/trans.png)
[英]Type or namespace name could not be found (missing using directive or assembly reference?)
[英]The type or namespace name 'form2' could not be found (are you missing a using directive or an assembly reference?)
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。
還有其他想法嗎?
就我而言,我創建了form2
,但后來對其進行了重命名。
我發現盡管表單的名稱已更改,但類的名稱仍與我最初創建時相同。
例如:1. Project-> Add Windows Form ( Setup.cs
)2. File-> Save Setup.cs as ... ( frmSetup.cs
)3.添加代碼:frmSetup SetupForm = new frmSetup();
但是,Setup類的實際名稱沒有隨文件名更改,因此將我的代碼更改為:
Setup SetupForm = new Setup();
所以我是在引用類名,而不是文件名為我解決了問題。
右鍵單擊Form2,選擇“解決”並選擇其中一種解決方案,或者將其移至WindowsFormsApplication3
命名空間。
您可以通過兩種方式解決此問題:
兩種形式應具有相同的名稱空間
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.