我打算让用户在 RunTime
期间创建 Forms
并将它们添加到项目中。我在开源 Form Designer
的帮助下完成了表单的设计和 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 调用)。因此,如果您通过简单的字符串操作将它与设计器代码合并,您的工作将会更容易。
关于c# - 如何将用户设计的窗体编译添加到工程中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17977993/