名前空間Editor
の一部であるという名前のユーザーコントロールがあります。StackCustomWindow
名前StackCustomWindow
空間には、プログラムのメインフォームが含まれています。デザイナを使用してユーザーコントロールをメインウィンドウに追加すると、Editor
VisualStudio2010は次のようなコードをデザイナに配置します。
this.editor1 = new StackCustomWindow.Editor();
これだけの場合:
this.editor1 = new Editor();
コンパイルすると例外がスローされます。
エラー1タイプ名'Editor'がタイプに存在しません
'StackCustomWindow.StackCustomWindow' C:\ Users \ ricardo \ Documents \ Visual Studio
2010 \ Projects \ StackCustomWindow \ StackCustomWindow \ StackCustomWindow.Designer.cs 35 51 StackCustomWindow
同様の質問を見つけました。ソリューションのどこかに重複した名前が存在する必要があるというソリューションがありますが、a)その名前の他のコントロールがないため、この場合になぜそれが存在するのかわかりません。b)重複する名前が実際に存在するかどうかを確認する方法がわかりません。他に、という名前のユーザーコントロールやアイテムはありませんが、VisualStudioはすべてEditor
のユーザーコントロールに対してこれを実行します。以下に示すように、すべてのコードは非常に基本的であり、ユーザーコントロールとメインウィンドウ以外のコントロールはありません。
のコードEditor
:
System.Windows.Formsを使用します。
namespace StackCustomWindow
{
public partial class Editor : UserControl
{
public Editor()
{
InitializeComponent();
}
}
}
そしてそれはdesigner.cs
ファイルです:
namespace StackCustomWindow
{
partial class Editor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Editor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "Editor";
this.Size = new System.Drawing.Size(452, 276);
this.ResumeLayout(false);
}
#endregion
}
}
StackCustomWindow.cs:
System.Windows.Formsを使用します。
namespace StackCustomWindow
{
public partial class StackCustomWindow : Form
{
public StackCustomWindow()
{
InitializeComponent();
}
}
}
StackCustomWindow.designer.cs:
namespace StackCustomWindow
{
partial class StackCustomWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// StackCustomWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(718, 535);
this.Name = "StackCustomWindow";
this.Text = "StackCustomWindow";
this.ResumeLayout(false);
}
#endregion
}
}