用VisualC#创建Windows应用程序-示例.doc

用VisualC#创建Windows应用程序-示例.doc

  1. 1、本文档共7页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
用VisualC#创建Windows应用程序-示例

用Visual C# 创建Windows应用程序-示例 在Visual C#创建一个Windows (GUI) 应用程序要以前版本的VC++ 容易得多。下面将介绍用Visual C#工程文件向导创建Windows应用程序的过程。 创建应用程序框架 在VS .NET IDE中选择“新建-工程文件-Visual C# 工程文件-Windows 应用程序”: 然后点击 OK,出现一个表单设计视图(这与VB或Delphi相同)。在右侧我们看到了一个解决方案导航器( Solution Explorer)。向导为新表单增加了一个Form1.cs 文件,其中包括了这个表单及其所有子窗口的的代码: ? 双击 Form1.cs就能看到这个代码: namespace mcWinFormsApp { using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.WinForms; using System.Data; /// summary /// Summary description for Form1. /// /summary public class Form1 : System.WinForms.Form { /// summary /// Required designer variable. /// /summary private System.ComponentModel.Container components; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// summary /// Clean up any resources being used. /// /summary public override void Dispose() { base.Dispose(); components.Dispose(); } /// summary /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// /summary private void InitializeComponent() { ponents = new System.ComponentModel.Container (); //@this.TrayHeight = 0; //@this.TrayLargeIcon = false; //@this.TrayAutoArrange = true; this.Text = Form1; this.AutoScaleBaseSize = new System.Drawing.Size (5, 13); this.Click += new System.EventHandler (this.Form1_Click); } protected void Form1_Click (object sender, System.EventArgs e) { } /// summary /// The main entry point for the application. /// /summary public static void Main(string[] args) { Application.Run(new Form1()); } } } 从以上代码中,我们看到:向导增加了一个默认的名称空间以及对WinForms 所要求的不同名称空间的引用;Form1 类是从System.WinForms.Form中派生出来的;InitializeComponent方法负责初始化(创建)表单及其控件(当在表单中托放下一些控件时,可以看到它的更多细节);Dispose方法负责清除所有不再使用的资源 。 添加控件 要向一个表单中添加控件或者子窗口,需要打开 工具箱ToolBox。这个工具箱的概念来自VB。点击菜单“视图-工具箱”,激活工具箱功能: ToolBox(工具箱)窗口的样子如下图所示。现在就可以添加控件了,

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档