在记事本中输入以下代码:
using System;
using System.Windows.Forms;
using System.Drawing;
class Form1 :Form
{
public Form1()
{
Button b = new Button();
b.Size = new Size(50, 30);
b.Location = new Point(50, 50);
b.Text = "OK";
b.Click +=new EventHandler(b_Click);
this.Controls.Add(b);
}
private void b_Click(object sender, EventArgs e)
{
MessageBox.Show("hello,world");
}
static void Main()
{
Form1 f = new Form1();
f.ShowDialog();
}
}
用CSC命令编译此文件后,运行时会出现一个控制台和一个窗体,这是我们不愿看到的,我们需要的只是一个窗体,那如何才能做
才不会出现此控制台呢?哪位朋友能帮个忙,不胜感激!!!
using System;
using System.Windows.Forms;
using System.Drawing;
class Form1 :Form
{
public Form1()
{
Button b = new Button();
b.Size = new Size(50, 30);
b.Location = new Point(50, 50);
b.Text = "OK";
b.Click +=new EventHandler(b_Click);
this.Controls.Add(b);
}
private void b_Click(object sender, EventArgs e)
{
MessageBox.Show("hello,world");
}
static void Main()
{
Form1 f = new Form1();
f.ShowDialog();
}
}
用CSC命令编译此文件后,运行时会出现一个控制台和一个窗体,这是我们不愿看到的,我们需要的只是一个窗体,那如何才能做
才不会出现此控制台呢?哪位朋友能帮个忙,不胜感激!!!
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(206, 78);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 265);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1;
参考
csc默认编译出的是一个控制台程序.
自然就有一个控制台.
如果要编译出win程序要加一条参数:/t:winexe具体其它还有很多参数.
LZ可以去查SDK
using System.Windows.Forms;namespace SimpleWFApp
{ class Program
{
static void Main()
{
Application.Run(new MainWindow());
}
} class MainWindow : Form
{
Button b = new Button(); public MainWindow()
{ b.Text = "一个按钮";
this.Controls.Add(b);
b.Click += new EventHandler(BClick);
} void BClick(object sender, EventArgs e)
{
MessageBox.Show("点击了按钮");
}
}
}
然后:csc /t:winexe 路径是可以的9楼正解