用C#手动写一个Windows窗体程序

首先,新建一个空项目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,运行即可。程序运行画面如下:

testform

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值