首先,新建一个空项目testForm。然后在解决方案栏点testForm解决方案,增加一个C#类,类名叫testForm.
写如下的代码:
using
System;
using
System.Drawing;
using
System.Windows.Forms;
namespace
testForm
{
///<summary>
/// testForm
///
测试手动编写一个windows应用程序,显示“你好,中国!”
///
作者:周海汉
///
日期:2006-7-10
///
版权:没有
///
联系方式:ablozhou@gmail.com
///</summary>
public class testForm
{
public testForm()
{
}
public static void Main()
{
MyForm form = new MyForm();
Application.Run(form);
}
}
public class MyForm:Form
{
public MyForm()
{
Label testLabel = new Label();
testLabel.Text ="
你好,中国!";
ClientSize = new Size(500, 400);
testLabel.Location = new Point(200,180);
Controls.AddRange(new Control[] {testLabel});
Text="
周海汉的测试!";
}
}
}
编译时告诉你System.Drawing和System.Windows不存在。在解决方案资源管理器里增加对 System.Drawing.dll和System.Windows.Forms.dll的引用,就可以生成最简单一个windows程序了。回想用Windows API编写windows应用程序,那对一个初学者可不那么好懂。而在dotnet下,很简单。定义一个类:MyForm,继承自Form。然后在MyForm构造函数里面增加一些控件。再到主函数里面去new这个form,运行即可。程序运行画面如下: