我一直在玩没有visual studio的小窗体应用程序。
我在Notepad ++中创建我的源代码并使用NAnt构建文件进行编译。
当我运行应用程序时,还会显示一个命令窗口以及应用程序窗口。如何阻止显示命令窗口?
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Media;
using System.IO;
namespace mynamespace
{
class MyForm : Form
{
public Button btnPlay;
MyForm()
{
this.SuspendLayout();
this.Text = "My Application";
InitialiseForm();
this.ResumeLayout(false);
}
private void InitialiseForm()
{
btnPlay = new Button();
btnPlay.Location = new System.Drawing.Point(30,40);
btnPlay.Text = "Play";
btnPlay.Click += new System.EventHandler(btnPlay_Click);
this.Controls.Add(btnPlay);
}
protected void btnPlay_Click(object sender, EventArgs e)
{
string wav = "testing123.wav";
Stream resourceStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(wav);
SoundPlayer player = new SoundPlayer(resourceStream);
player.Play();
}
public static void Main()
{
Application.Run(new MyForm());
}
}
}
构建文件
<?xml version="1.0"?>
<project name="myform" default="build" basedir=".">
<description>My Form app</description>
<property name="debug" value="true" overwrite="false"/>
<target name="clean" description="Remove all generated files">
<delete dir="build"/>
</target>
<target name="build" description="Compile the source" depends="clean">
<mkdir dir="build"/>
<csc target="exe" output="build\MyForm.exe" debug="${debug}" verbose="true">
<resources>
<include name="app\resources\*.wav" />
</resources>
<sources>
<include name="app\MyForm.cs"/>
</sources>
</csc>
</target>
</project>
答案 0 :(得分:2)
好的,我有,我需要指定target =“winexe”而不是target =“exe”