c# - 如何将用户设计的窗体编译添加到工程中

标签 c# winforms dll compilation exe

我打算让用户在 RunTime 期间创建 Forms 并将它们添加到项目中。我在开源 Form Designer 的帮助下完成了表单的设计和 UI。

这是表单设计器的图像:image

假设我有 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 调用)。因此,如果您通过简单的字符串操作将它与设计器代码合并,您的工作将会更容易。

关于c# - 如何将用户设计的窗体编译添加到工程中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17977993/

相关文章:

winforms - 从 http flurl 客户端捕获异常时出现问题

c# - c# Winforms中不存在时如何创建数据库

java - 无法在 Java Applet 中将文件设置为可写

c++ - Qt 5.2 DLL 返回与调用 DLL 的应用程序不同的结果

python - ctypes找不到find dll函数

c# - 为什么我可以声明一个与父作用域中的变量同名的子变量?

c# - 在 Xamarin 中使用 C# 将字节数组转换为图像

c# - 从上传的视频流生成缩略图?

c# - SelectNodes 不适用于 stackoverflow 提要

c# - 在 c# winform 应用程序中插入/保存/提交数据后的空文本框控件