C# 表单1在当前上下文中不存在
伙计们,我正在用c#制作一个媒体播放器,当我点击一个按钮时,有一个代码将表单1重定向到表单2,该代码在前4个表单上工作(我是说表单1、表单2、表单3…),然后我添加了表单5,但在表单5中,当我键入重定向代码时,我得到了这个错误“表单1在当前上下文中不存在”这是我的Designer.csC# 表单1在当前上下文中不存在,c#,visual-studio,C#,Visual Studio,伙计们,我正在用c#制作一个媒体播放器,当我点击一个按钮时,有一个代码将表单1重定向到表单2,该代码在前4个表单上工作(我是说表单1、表单2、表单3…),然后我添加了表单5,但在表单5中,当我键入重定向代码时,我得到了这个错误“表单1在当前上下文中不存在”这是我的Designer.cs namespace MineMusic { partial class Form5 { /// <summary> /// Required designer vari
namespace MineMusic
{
partial class Form5
{
/// <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();
//
// Form5
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(830, 470);
this.Name = "Form5";
this.Text = "Form5";
this.Load += new System.EventHandler(this.Form5_Load);
this.ResumeLayout(false);
}
#endregion
}
在InitializeComponent中,设计器使用快捷方式时,分部类名为Shortcut1。这可能是你的问题。你能给我们看一下“重定向”代码吗?也许你是在直接重命名你的表单,而不是使用右键单击>重构?我只是输入了一个错误的代码。你提供了类Form5和创建Form2实例的代码,但得到了错误“Form1没有…”?
Form2 f2 = new Form2();
this.Hide();
f2.ShowDialog();