C# 如何编译用户设计的表单并将其添加到项目中

C# 如何编译用户设计的表单并将其添加到项目中,c#,winforms,dll,compilation,exe,C#,Winforms,Dll,Compilation,Exe,我将允许用户在运行时创建表单,并将它们添加到项目中。在开源表单设计器的帮助下,我完成了表单的设计和UI 以下是表单设计器的图像: 假设我有Form1.cs和Form1.cs[Designer]文件,这些文件对于WinForm来说足够了。但是如何将其编译为DLL或EXE并添加到项目中呢?有什么想法吗?有什么线索吗 谢谢 编辑 它创建了这个代码 public partial class Form1 : Form { public Form1() { Initializ

我将允许用户在
运行时创建
表单
,并将它们添加到项目中。在开源
表单设计器的帮助下,我完成了表单的设计和UI

以下是
表单设计器的图像

假设我有Form1.cs和Form1.cs[Designer]文件,这些文件对于
WinForm
来说足够了。但是如何将其编译为DLL或EXE并添加到项目中呢?有什么想法吗?有什么线索吗

谢谢

编辑

它创建了这个代码

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private System.Windows.Forms.Button button1;

    private System.Windows.Forms.TextBox textBox1;

    private System.Windows.Forms.CheckBox checkBox1;


    private void InitializeComponent()
    {
        this.button1 = new System.Windows.Forms.Button();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.checkBox1 = new System.Windows.Forms.CheckBox();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(71, 49);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 0;
        this.button1.Text = "button1";
        this.button1.UseCompatibleTextRendering = true;
        this.button1.UseVisualStyleBackColor = true;
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(71, 94);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(100, 20);
        this.textBox1.TabIndex = 1;
        // 
        // checkBox1
        // 
        this.checkBox1.Location = new System.Drawing.Point(38, 184);
        this.checkBox1.Name = "checkBox1";
        this.checkBox1.Size = new System.Drawing.Size(104, 24);
        this.checkBox1.TabIndex = 2;
        this.checkBox1.Text = "checkBox1";
        this.checkBox1.UseCompatibleTextRendering = true;
        this.checkBox1.UseVisualStyleBackColor = true;
        // 
        // form1
        // 
        this.ClientSize = new System.Drawing.Size(292, 273);
        this.Controls.Add(this.checkBox1);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.button1);
        this.Name = "form1";
        this.ResumeLayout(false);
        this.PerformLayout();
    }


}

我将自己对代码的其余部分进行一些额外的编码。但我不知道如何编译它并将其添加到主exe?

线索是System.CodeDom.Compiler
我认为Form1.cs将不包含任何代码(除了在构造函数中调用InitializeComponents)。因此,如果您将其与设计器代码合并,并使用简单的字符串操作,您的工作将更轻松。

我编辑了我的问题。我会像你说的那样做简单的字符串操作。但是我应该如何将新创建的wiwnform添加到主exe?你不能。唯一的解决方法是将main.exe复制到另一个位置并对其进行修改。然后使用单独的简单exe,在关闭main.exe之前启动它,并让它将其移动到所需位置。但如果我是您,我会将生成的dynamicali创建的程序集保存到/DynamicForms这样的位置,然后像您的另一个问题一样从中加载。