欢迎来到天天文库
浏览记录
ID:41004538
大小:38.31 KB
页数:4页
时间:2019-08-13
《从头开始编写Windows窗体应用程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、从头开始编写Windows窗体应用程序1创建一个最简单的Windows窗体程序1.1在VS2008中创建一个空项目(EmptyProject)1.2添加新项目:CodeFile.cs1.3添加引用程序集:§System§System.Windows.Forms1.4在CodeFile.cs中输入:usingSystem;usingSystem.Windows.Forms;namespaceASimplestWindowsForm{publicclassForm1:Form{publicForm1(){}[STAT
2、hread]publicstaticvoidMain(){Application.EnableVisualStyles();Application.Run(newForm1());}}}1.5编译运行(见下图)1添加Button控件1.1添加新的引用程序集:§System.Drawing1.2在CodeFile.cs中输入(加粗字体为新添加部分):usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;namespaceASimplestWindowsF
3、orm{publicclassForm1:Form{publicButtonbutton1;publicForm1(){button1=newButton();button1.Size=newSize(80,40);button1.Location=newPoint(30,30);button1.Text="Clickme";this.Controls.Add(button1);}[STAThread]publicstaticvoidMain(){Application.EnableVisualStyles();
4、Application.Run(newForm1());}}}1.1编译运行(见下图)2添加Button控件单击事件处理2.1在CodeFile.cs中输入(加粗字体为新添加部分):usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;namespaceASimplestWindowsForm{publicclassForm1:Form{publicButtonbutton1;publicForm1(){button1=newButton();butt
5、on1.Size=newSize(80,40);button1.Location=newPoint(30,30);button1.Text="Clickme";this.Controls.Add(button1);button1.Click+=newEventHandler(button1_Click);}privatevoidbutton1_Click(objectsender,EventArgse){MessageBox.Show("HelloWorld");}[STAThread]publicstaticv
6、oidMain(){Application.EnableVisualStyles();Application.Run(newForm1());}}}1.1编译运行(见下图)2
此文档下载收益归作者所有