0

我刚刚创建了一个使用 C# 编译器以编程方式编译代码的小应用程序,它运行良好。但是,我需要它做的一件事是编译 Windows.Forms 代码。就像,我可以用它创建一个控制台应用程序,但我不能创建一个基于 GUI 的表单。这是让我开始的链接:

http://support.microsoft.com/kb/304655

有人可以帮忙吗?

谢谢 :)

更新

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

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

        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("hi jason");
        }
    }
}

上面的代码是我在我的应用程序中输入的。当我尝试编译这段代码时,我的应用程序给了我很多错误,并且没有生成 exe(显然)。但是,我的应用程序总是成功编译直接控制台应用程序......

4

3 回答 3

3

You have the same problem I did.

All you need to do is tell the compiler to compile the program as winexe. To do this, simply add this to your CompilerParams:

CompilerParams.CompilerOptions = "/target:winexe";

But also note, that will compile it with the default icon (which looks horrible!), so you will need to add additional arguments to that:

if (File.Exists(iconPath))
    CompilerParams.CompilerOptions = "/target:winexe" + " " + "/win32icon:" + "\"" + iConPath + "\"";
else
    CompilerParams.CompilerOptions = "/target:winexe";

This way it will check to see if the icon exists before trying to put it in, to save you a bit of trouble that I had to go through....

于 2010-09-18T20:35:37.650 回答
1

您只需要在编译时添加System,System.DrawingSystem.Windows.Forms程序集作为引用

于 2010-04-17T19:02:24.713 回答
1

You need to include both the Form1.cs and Form1.Designer.cs to fully compile it. Of course, you have to include references to the Forms and any other needed namespace as well.

于 2010-04-17T19:06:08.107 回答