C#程序生成exe问题(是在程序中生成)
意思就是 在主窗体弄一个按钮 然后再新建一个窗体 在主窗体上点击那个按钮 然后新建的窗体单独生成一个exe文件在当前目录下 打开那个exe文件就是一个单独的软件 是新建窗体的那个 嗯嗯 就这些 不知道咋弄的 希望大家帮忙下
最近 接了个项目 不会这个啊 求帮忙下 谢谢咯。。
private void ButGenerate_Click(object sender, EventArgs e) { const string codeString = "using System;using System.Windows.Forms;using System.Drawing;namespace NewFormNameSpace{static class Program{[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new NewForm());}} public class NewForm : Form{private components = null;protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}public NewForm(){InitializeComponent();}private void InitializeComponent(){this.SuspendLayout();this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(300, 200);this.Name = \"NewForm\";this.Text = \"I am a form !\";this.ResumeLayout(false);this.PerformLayout();}}}"; var csProvider = CodeDomProvider.CreateProvider("CSharp"); var cParameter = new CompilerParameters { GenerateExecutable = true, GenerateInMemory = false, OutputAssembly = "NewForm.exe", CompilerOptions = "/t:winexe" }; cParameter.ReferencedAssemblies.AddRange(new[] { "System.dll", "System.Drawing.dll", "System.Windows.Forms.dll" }); (cParameter, codeString); }