ParentForm.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:4k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. namespace SimpleMDIApp
  8. {
  9. /// <summary>
  10. /// Summary description for Form1.
  11. /// </summary>
  12. public class ParentForm : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.MainMenu menuMain;
  15. private System.Windows.Forms.MenuItem menuFile;
  16. private System.Windows.Forms.MenuItem menuFileNew;
  17. private System.Windows.Forms.MenuItem menuFileExit;
  18. private System.Windows.Forms.MenuItem menuWin;
  19. private System.Windows.Forms.MenuItem menuItem1;
  20. /// <summary>
  21. /// Required designer variable.
  22. /// </summary>
  23. private System.ComponentModel.Container components = null;
  24. public ParentForm()
  25. {
  26. //
  27. // Required for Windows Form Designer support
  28. //
  29. InitializeComponent();
  30. //
  31. // TODO: Add any constructor code after InitializeComponent call
  32. //
  33. }
  34. /// <summary>
  35. /// Clean up any resources being used.
  36. /// </summary>
  37. protected override void Dispose( bool disposing )
  38. {
  39. if( disposing )
  40. {
  41. if (components != null) 
  42. {
  43. components.Dispose();
  44. }
  45. }
  46. base.Dispose( disposing );
  47. }
  48. #region Windows Form Designer generated code
  49. /// <summary>
  50. /// Required method for Designer support - do not modify
  51. /// the contents of this method with the code editor.
  52. /// </summary>
  53. private void InitializeComponent()
  54. {
  55. this.menuMain = new System.Windows.Forms.MainMenu();
  56. this.menuFile = new System.Windows.Forms.MenuItem();
  57. this.menuFileNew = new System.Windows.Forms.MenuItem();
  58. this.menuFileExit = new System.Windows.Forms.MenuItem();
  59. this.menuWin = new System.Windows.Forms.MenuItem();
  60. this.menuItem1 = new System.Windows.Forms.MenuItem();
  61. // 
  62. // menuMain
  63. // 
  64. this.menuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  65.  this.menuFile,
  66.  this.menuWin});
  67. // 
  68. // menuFile
  69. // 
  70. this.menuFile.Index = 0;
  71. this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  72.  this.menuFileNew,
  73.  this.menuItem1,
  74.  this.menuFileExit});
  75. this.menuFile.Text = "File";
  76. // 
  77. // menuFileNew
  78. // 
  79. this.menuFileNew.Index = 0;
  80. this.menuFileNew.Text = "New";
  81. this.menuFileNew.Click += new System.EventHandler(this.mnuFileNew_Click);
  82. // 
  83. // menuFileExit
  84. // 
  85. this.menuFileExit.Index = 2;
  86. this.menuFileExit.Text = "Exit";
  87. // 
  88. // menuWin
  89. // 
  90. this.menuWin.Index = 1;
  91. this.menuWin.MdiList = true;
  92. this.menuWin.MergeOrder = 3;
  93. this.menuWin.Text = "Window";
  94. // 
  95. // menuItem1
  96. // 
  97. this.menuItem1.Index = 1;
  98. this.menuItem1.Text = "Another New";
  99. this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
  100. // 
  101. // ParentForm
  102. // 
  103. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  104. this.ClientSize = new System.Drawing.Size(552, 385);
  105. this.IsMdiContainer = true;
  106. this.Menu = this.menuMain;
  107. this.Name = "ParentForm";
  108. this.Text = "Form1";
  109. }
  110. #endregion
  111.     private void mnuFileNew_Click(object sender, System.EventArgs e)
  112.     {
  113.       ChildForm frm = new ChildForm();
  114.       frm.Name = string.Concat("MDIChildForm", this.MdiChildren.Length.ToString());
  115.       frm.Text = frm.Name;
  116.       frm.MdiParent = this;
  117.       frm.Show();
  118.     }
  119. private void menuItem1_Click(object sender, System.EventArgs e)
  120. {
  121.       AnotherChildForm frm = new AnotherChildForm();
  122.       frm.Name = string.Concat("AnotherMDIChildForm", this.MdiChildren.Length.ToString());
  123.       frm.Text = frm.Name;
  124.       frm.MdiParent = this;
  125.       frm.Show();
  126. }
  127.     
  128. }
  129. }