繁体   English   中英

表单和设计器文件未在解决方案资源管理器

[英]Form and designer files not linking in Solution Explorer

我似乎无法将表单和设计器文件链接到我的项目中。 它们在Solution Explorer中看起来像这样。

在此输入图像描述

我已从项目中排除了文件,然后尝试将它们包含在项目中,但这不起作用。 下面是设计器代码和表单代码的片段,以防有什么内容。

public partial class FormPrompt
{
  private Button ButtonOk;
  private Container Components;
  private Label LabelPleaseEnter;
  private Label LabelPrompt;
  private TextBox TextBoxData;

  private void InitializeComponent()
  {
    this.LabelPleaseEnter = new Label();
    this.LabelPrompt = new Label();
    this.TextBoxData = new TextBox();
    this.ButtonOk = new Button();
    this.LabelPleaseEnter.Location = new Point(8, 0x58);
    this.LabelPleaseEnter.Size = new Size(0x48, 0x10);
    this.LabelPleaseEnter.Text = "Please enter";
    this.LabelPrompt.Location = new Point(80, 0x58);
    this.LabelPrompt.Size = new Size(0x98, 0x10);
    this.LabelPrompt.Text = "LabelPrompt";
    this.TextBoxData.Location = new Point(8, 0x80);
    this.TextBoxData.Size = new Size(0xe0, 20);
    this.TextBoxData.Text = "TextBoxData";
    this.TextBoxData.KeyDown += new KeyEventHandler(this.FormPrompt_KeyDown);
    this.ButtonOk.Location = new Point(8, 0x100);
    this.ButtonOk.Size = new Size(0xe0, 0x38);
    this.ButtonOk.Text = "Ok";
    this.ButtonOk.Click += new EventHandler(this.ButtonOk_Click);
    base.ClientSize = new Size(240, 0x13e);
    base.Controls.Add(this.TextBoxData);
    base.Controls.Add(this.ButtonOk);
    base.Controls.Add(this.LabelPrompt);
    base.Controls.Add(this.LabelPleaseEnter);
    this.Text = "WinForm";
    base.KeyDown += new KeyEventHandler(this.FormPrompt_KeyDown);
  }
}    


public partial class FormPrompt : Form
{

  internal DateTime FDateData;
  internal DateTimePicker FDatePicker;
  internal decimal FDecimalData;
  internal int FIntData;
  internal TPromptType FPromptType;
  internal string FStringData;


  public FormPrompt()
  {
    this.InitializeComponent();
    this.FDatePicker = new DateTimePicker();
    this.FDatePicker.Top = this.TextBoxData.Top;
    this.FDatePicker.Left = this.TextBoxData.Left;
    this.FDatePicker.Width = this.TextBoxData.Width;
    this.FDatePicker.Height = this.TextBoxData.Height;
    this.FDatePicker.Format = DateTimePickerFormat.Short;
    base.Controls.Add(this.FDatePicker);
  }
}

我在Visual Studio 2008中看到了同样的问题。通常在编译或关闭并重新打开解决方案后,问题就会自行解决。 在Visual Studio 2012中,如果我尝试添加>现有项目并选择所有三个文件,我知道我有问题。 通常,您只想添加顶级form.cs,VS将自动包含.designer.cs和.resx文件。

检查项目( .csproj )文件。

ItemGroup节点内,查看.designer文件是否与代码隐藏文件相关联。 XML应如下所示:

<Compile Include="FormPrompt.cs">
    <SubType>Form</SubType>
</Compile>
<Compile Include="FormPrompt.Designer.cs">
    <DependentUpon>FormPrompt.cs</DependentUpon>
</Compile>

在VS2017(c#)中解决它,在我的情况下:

  1. 排除所有文件
  2. 去文件夹
  3. 重命名文件(全部3个文件.cs.Designer.cs .resx)
  4. 刷新解决方案
  5. 添加到项目中

检查项目(.csproj)

<EmbeddedResource Include="Properties\Resources.resx">
  <Generator>ResXFileCodeGenerator</Generator> Check this
  <SubType>Designer</SubType>
  <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>

<Compile Include="Properties\Resources.Designer.cs">
  <AutoGen>True</AutoGen> And Check this
  <DesignTime>True</DesignTime>
  <DependentUpon>Resources.resx</DependentUpon>
</Compile>

将.resx文件包含到项目中,并在此文件的属性中将Custom Tool设置为ResXFileCodeGenerator

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM