
ZJWCHC 第四章 2☑/78 WinForms:基础知识
ZJWCHC 第四章 WinForms基础知识

目标 ◆理解Windows窗体 ◆使用基本控件如标签、文本、按钮、列表框和组 合框 ◆掌握窗体的常用属性和方法 ◆使用WinForms中的高级控件 。单选按钮 。图片框 ·选项卡控件 ·滚动条 ·进度条 2
2 目标 理解 Windows 窗体 使用基本控件如标签、文本、按钮、列表框和组 合框 掌握窗体的常用属性和方法 使用WinForms中的高级控件 单选按钮 图片框 选项卡控件 滚动条 进度条

简介2-1 示屈性 3 X 背景屏幕保护程序外观b效果设置1 丰活动窗口 回☒ 活动窗口 回x 一般无效已选定 窗口文字 消息框 ☒ 消息内容 确定 控件 方案③) 习另存为册除四才 项目): 大小):颜色):颜色2 活动窗口标题栏 习18日时☐的 字体迎): 大小):颜色⑧): Tahoma B▣▣B 确定☐取消☐应用
3 简介2-1 GUI界面 控件

日▣☒ 文件)编辑正)视图们项目企)生成B)调试①)数据)格式0)工具T)侧试S)窗口W)社区C)帮助D ,园,3日电9N Debug·ycU 工具箱 Por1.cs[设计]起始页 X 解决方案资源管理器-Windowshpplication3 X 所有Tindows自体 9网国8 指针 ☒ ication3”个项目 界Backgroun ☑Bindineay 各种控件 属性 Button Checkedli orml Systen.Windows.Forms.Forn ConboBox 放置控件的区域 FormBorderStvle Sih1。 ContextMenuStrip HelpButton False 目DateGridViev 目DataSet ontrol DateTimePicke Language DonainUpDown Localizable Location ErrorProvider 00 EventLog MaxinunSize 0,0 MininizeBox GroupBox F1 HelpProvi der HSerollBar 控件关联的文本。 输出之查找衍号结果 就储
4 各种控件 属性 放置控件的区域

简介2-2 System.Windows.Forms 简单而强大 改善了接▣和基类IntelliSense 新的管理数据提供程序 安全 灵活的控件 通晓数据 向导 WinForms)应用程序可能存在多个窗体,用于获取用户输入的 数据和向用户显示数据 5
5 简介 2-2 WinForms应用程序可能存在多个窗体,用于获取用户输入的 数据和向用户显示数据 System.Windows.Forms 简单而强大 改善了接口和基类 IntelliSense 新的管理数据提供程序 安全 灵活的控件 通晓数据 向导

创建WinForms应用程序6-1 “开始”→“程序”→“Microsoft Visual Studio..NET2005”→“Microsoft Visual indovzApplication3-Microsoft Visunl Studio 口回☒ 工具四试专口)区) 打开 加 文件 从现有代码注项目) Visual Studio 2005 近的项目 Fornl.es 的暂界 的文件 ty1。 最近的项目口 开始 关联的文本 6
6 创建 WinForms应用程序 6-1 “开始”→“程序”→“Microsoft Visual Studio.NET 2005”→“Microsoft Visual Studio.NET 2005

VindowsApplication3-Nicrosoft Visual Studio 日▣☒ 文件)编辑)视图)项目)生成⑧)调试)数据么)格式@)工具)试S)窗口W)社区C)帮助0 个,园,3日0造9,N月3 Debug Any CPU 工具箱 Por1.cs[设计]起始页 、X解决方案资源管理器-?indowsApplication3 所有■indors窗体 品国员 指针 Fon 日▣☒ Bindinglavigator Button 设计窗口 Forml Systen.Windows.Forms.Forn ColorDialog 2国¥国 ConboBox Locked 图ContextlenuStrip MainenuStrip 无) 目DataGridView 0.0 Opacity 100g Padding ■DonainUpDown ErrorProvider 图EventLog 用Sixe 341,300 Auto FontDio StartPosition GroupBox 回HelpProvider HSerollBar InageList 件关联的文本 就储 15,15 挡341x300
7 创建 WinForms应用程序 6-2 设计窗口

创建WinForms.应用程序6-3 using System; 基础核心命名空间 using System.Collections.Generic; 定供丁大量绘图工具的访问权限 using System.ComponentModel; ArrayList、BitArray、Hashtable、Stack, using System.Data; StringCollection和String Table类 using System.Drawing; using System.Text: using System.Windows.Forms; 大量窗体和控件 namespace WindowsApplication3 public partial class Form1 Form public Form10 InitializeComponent(); 从System.Nindows.Forms.Form派生 Visual Studio.NET生成的代码 8
8 创建 WinForms应用程序 6-3 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } } } 提供了大量绘图工具的访问权限 基础核心命名空间 ArrayList、BitArray、Hashtable、Stack、 StringCollection 和 StringTable 类 大量窗体和控件 从 System.Windows.Forms.Form 派生 Visual Studio .NET 生成的代码

创建WinForms应用程序6-4 #region Windows窗体设计器生成的代码 /// 川设计器支持所需的方法.不要 川使用代码编辑器修改此方法的内容 项目的容器 ll/ private void InitializeComponent() this.SuspendLayout(); ∥Form1 this.AutoScaleDimensions new System.Drawing.SizeF(6F,12F); this.AutoScaleMode System.Windows.Forms.AutoScaleMode.Font; this.ClientSize=new System.Drawing.Size(333,266); this.Name "Form1"; this.Text ="Form1"; this.ResumeLayout(false); #endregion
9 创建 WinForms应用程序 6-4 partial class Form1 { /// /// 必需的设计器变量。 /// private System.ComponentModel.IContainer components = null; 构造函数调用 InitializeComponent() 方法 #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { this.SuspendLayout(); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(333, 266); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion 项目的容器

创建WinForms应用程序6-5 /// 川清理所有正在使用的资源。 /// W如果应释放托管资源,为true:否则为 false。 protected override void Dispose(bool disposing) if(disposing &&(components !null)) { components.Dispose(); base.Dispose(disposing); 释放系统资源 o
10 创建 WinForms应用程序 6-5 /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } 释放系统资源