210 likes | 345 Views
第 6 章 多窗体工程. 项目 — 添加 Windows 窗体. 每个窗体都被保存为 3 个独立的文件,扩展名分别为 . cs . designer.cs . resx ,窗体的所有信息都保存在这三个文件中. 解决方案资源管理器 文档窗口标签 活动文件按钮. 窗体间的切换. 添加现有项. 项目 — 添加现有项. About 对话框. Displaying an About Form. // Create a new instance of the AboutBox1 form class.
E N D
每个窗体都被保存为3个独立的文件,扩展名分别为.cs .designer.cs .resx,窗体的所有信息都保存在这三个文件中
解决方案资源管理器 文档窗口标签 活动文件按钮 窗体间的切换
添加现有项 项目—添加现有项
Displaying an About Form // Create a new instance of the AboutBox1 form class. AboutBox1 aboutForm = new AboutBox1(); // Show the new aboutForm object. aboutForm.ShowDialog(); • 创建新实例 Show方法或者showdialog显示对象
使用窗体的方法和事件 Close方法对非模态窗体(Show方法)与模态窗体(Showdialog方法)表现不同行为。对于非模态窗体,Close方法销毁窗体实例,并将其从内存中删除;对模态窗体而言,Close方法只是将窗体隐藏而已。
Hide() Hide方法,隐藏某个窗体,但继续将其保留在内存中,为再次显示做准备。
响应窗体事件 发生于Load之后,每次显示窗体Actiated事件再次发生 窗体被加载到内存 FormName.Load和FormName.Actiated
多窗体过程中的变量和常量 在类中创建属性 只读属性 只写属性P213 在多个窗体间传递汇总值(static静态变量)
The Property Block - Example private string lastNameString; public string LastName { get { return lastNameString; } set { lastNameString= value; } } Holds the value of the property Name of property Retrieve the value of the property Assign a value to the 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; } } 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)
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; } } 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)
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()); } Add these two statements to display the splash form MainForm is the name of the startup form – Change this if you change the startup form The Program.cs file with the code added to show the splash form
启动界面 添加窗体 设置StarPosition属性CenterScreen ControlBox False
Timer控件 Enabled Inteval
使用启动窗体 Program.cs –Main 方法 Application.Run(new Form1());
在IDE之外运行程序 Bin\Debug文件夹中.exe文件 前提:安装了.NET Framework, Visual Studio 2008 默认是.Net 3.5 修改图标工程—属性—应用程序选项—图标和清单(C)