1 / 21

第 6 章 多窗体工程

第 6 章 多窗体工程. 项目 — 添加 Windows 窗体. 每个窗体都被保存为 3 个独立的文件,扩展名分别为 . cs . designer.cs . resx ,窗体的所有信息都保存在这三个文件中. 解决方案资源管理器 文档窗口标签 活动文件按钮. 窗体间的切换. 添加现有项. 项目 — 添加现有项. About 对话框. Displaying an About Form. // Create a new instance of the AboutBox1 form class.

Télécharger la présentation

第 6 章 多窗体工程

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第6章 多窗体工程

  2. 项目—添加Windows窗体

  3. 每个窗体都被保存为3个独立的文件,扩展名分别为.cs .designer.cs .resx,窗体的所有信息都保存在这三个文件中

  4. 解决方案资源管理器 文档窗口标签 活动文件按钮 窗体间的切换

  5. 添加现有项 项目—添加现有项

  6. About对话框

  7. 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显示对象

  8. 使用窗体的方法和事件 Close方法对非模态窗体(Show方法)与模态窗体(Showdialog方法)表现不同行为。对于非模态窗体,Close方法销毁窗体实例,并将其从内存中删除;对模态窗体而言,Close方法只是将窗体隐藏而已。

  9. Hide() Hide方法,隐藏某个窗体,但继续将其保留在内存中,为再次显示做准备。

  10. 响应窗体事件 发生于Load之后,每次显示窗体Actiated事件再次发生 窗体被加载到内存 FormName.Load和FormName.Actiated

  11. 窗体事件顺序P211

  12. 多窗体过程中的变量和常量 在类中创建属性 只读属性 只写属性P213 在多个窗体间传递汇总值(static静态变量)

  13. 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

  14. 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)

  15. 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)

  16. 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

  17. 启动界面 添加窗体 设置StarPosition属性CenterScreen ControlBox False

  18. Timer控件 Enabled Inteval

  19. 使用启动窗体 Program.cs –Main 方法 Application.Run(new Form1());

  20. 在IDE之外运行程序 Bin\Debug文件夹中.exe文件 前提:安装了.NET Framework, Visual Studio 2008 默认是.Net 3.5 修改图标工程—属性—应用程序选项—图标和清单(C)

More Related