2.1 中文導覽手冊 - Rezwave · 3 第一章 介面介紹 (The TOPSPIN Interface) 1-1. 子視窗切換鍵 當光譜視窗內開啟多個視窗,或其他功能視窗(如溫度控制功
第 6 章 多窗体工程
-
Upload
stillman-tyrone -
Category
Documents
-
view
58 -
download
6
description
Transcript of 第 6 章 多窗体工程
![Page 1: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/1.jpg)
第 6 章 多窗体工程
![Page 2: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/2.jpg)
项目—添加 Windows 窗体
![Page 3: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/3.jpg)
每个窗体都被保存为 3 个独立的文件,扩展名分别为 .cs .designer.cs .resx ,窗体的所有信息都保存在这三个文件中
![Page 4: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/4.jpg)
窗体间的切换解决方案资源管理器
文档窗口标签活动文件按钮
![Page 5: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/5.jpg)
项目—添加现有项
添加现有项
![Page 6: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/6.jpg)
About 对话框
![Page 7: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/7.jpg)
创建新实例
Show 方法或者 showdialog 显示对象
Displaying an About Form
// Create a new instance of the AboutBox1 form class. AboutBox1 aboutForm = new AboutBox1();
// Show the new aboutForm object. aboutForm.ShowDialog();
![Page 8: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/8.jpg)
Close 方法对非模态窗体( Show 方法)与模态窗体( Showdialog 方法)表现不同行为。对于非模态窗体, Close 方法销毁窗体实例,并将其从内存中删除;对模态窗体而言, Close 方法只是将窗体隐藏而已。
使用窗体的方法和事件
![Page 9: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/9.jpg)
Hide 方法,隐藏某个窗体,但继续将其保留在内存中,为再次显示做准备。
Hide ()
![Page 10: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/10.jpg)
FormName.Load 和 FormName.Actiated
响应窗体事件
窗体被加载到内存
发生于 Load之后,每次显
示窗体Actiated 事件
再次发生
![Page 11: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/11.jpg)
事件Load 发生于初次显示窗体之前,该事件只发生一次,除非关闭而
非隐藏窗体。
Activated 显示窗体时都会发生。Paint 当窗体的任何部分被重画时发生Deactivate 发生与窗体不再是活动窗体时FormClosing 窗体即将关闭时发生。FormClosed 窗体关闭之后发生。
窗体事件顺序 P211
![Page 12: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/12.jpg)
在类中创建属性 只读属性 只写属性 P213 在多个窗体间传递汇总值( static 静态变量)
多窗体过程中的变量和常量
![Page 13: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/13.jpg)
The Property Block - Example
private string lastNameString;
public string LastName{ get { return lastNameString; } set { lastNameString = value; }}
Name of propertyRetrieve the value of the property
Assign a value to the property
Holds the value of the property
![Page 14: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/14.jpg)
In some instances, a property can be retrieved by an object but not changed
Write a property block that contains only a get (creates a read-only property)
Read-Only Properties
// Private class-level variable to hold the property value.private decimal payDecimal;
// Property block for read-only property.public decimal Pay{ get { return payDecimal; }}
![Page 15: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/15.jpg)
A property that can be assigned by an object but not retrieved
Write a property block that contains only a set (creates a write-only property)
Write-only Properties
// Private class-level variable to hold the property value.private decimal hoursDecimal;
// Property block for write-only property.public decimal Hours{ set { hoursDecimal = value; }}
![Page 16: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/16.jpg)
The Program.cs file with the code added to show the splash form
Making the Splash Form Display First - 2
static void Main(){ Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SplashForm aSplashForm = new SplashForm(); aSplashForm.ShowDialog(); Application.Run(new MainForm());}
MainForm is the name of the startup form – Change this if you change the startup form
Add these two statements to display the splash form
![Page 17: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/17.jpg)
添加窗体 设置 StarPosition 属性 CenterScreen ControlBox False
启动界面
![Page 18: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/18.jpg)
Enabled Inteval
Timer 控件
![Page 19: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/19.jpg)
Program.cs –Main 方法 Application.Run(new Form1());
使用启动窗体
![Page 20: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/20.jpg)
Bin\Debug 文件夹中 .exe 文件 前提:安装了 .NET Framework, Visual Studio
2008 默认是 .Net 3.5 修改图标工程—属性—应用程序选项—图标和清单
( C )
在 IDE 之外运行程序
![Page 21: 第 6 章 多窗体工程](https://reader035.fdocuments.net/reader035/viewer/2022081420/568137f2550346895d9fb38e/html5/thumbnails/21.jpg)