Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 6k
Category:

ADO-ODBC

Development Platform:

C#

  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 ch2_8
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.MainMenu mainMenu1;
  15. private System.Windows.Forms.MenuItem menuItem1;
  16. private System.Windows.Forms.MenuItem menuItem2;
  17. private System.Windows.Forms.MenuItem menuItem3;
  18. private System.Windows.Forms.MenuItem menuItem4;
  19. private System.Windows.Forms.MenuItem menuItem5;
  20. private System.Windows.Forms.MenuItem menuItem6;
  21. private System.Windows.Forms.MenuItem menuItem7;
  22. private System.Windows.Forms.OpenFileDialog openFileDialog1;
  23. /// <summary>
  24. /// 必需的设计器变量。
  25. /// </summary>
  26. private System.ComponentModel.Container components = null;
  27. public Form1()
  28. {
  29. //
  30. // Windows 窗体设计器支持所必需的
  31. //
  32. InitializeComponent();
  33. //
  34. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  35. //
  36. }
  37. /// <summary>
  38. /// 清理所有正在使用的资源。
  39. /// </summary>
  40. protected override void Dispose( bool disposing )
  41. {
  42. if( disposing )
  43. {
  44. if (components != null) 
  45. {
  46. components.Dispose();
  47. }
  48. }
  49. base.Dispose( disposing );
  50. }
  51. #region Windows Form Designer generated code
  52. /// <summary>
  53. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  54. /// 此方法的内容。
  55. /// </summary>
  56. private void InitializeComponent()
  57. {
  58. this.mainMenu1 = new System.Windows.Forms.MainMenu();
  59. this.menuItem1 = new System.Windows.Forms.MenuItem();
  60. this.menuItem2 = new System.Windows.Forms.MenuItem();
  61. this.menuItem3 = new System.Windows.Forms.MenuItem();
  62. this.menuItem4 = new System.Windows.Forms.MenuItem();
  63. this.menuItem5 = new System.Windows.Forms.MenuItem();
  64. this.menuItem6 = new System.Windows.Forms.MenuItem();
  65. this.menuItem7 = new System.Windows.Forms.MenuItem();
  66. this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
  67. // 
  68. // mainMenu1
  69. // 
  70. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  71.   this.menuItem1,
  72.   this.menuItem4});
  73. // 
  74. // menuItem1
  75. // 
  76. this.menuItem1.Index = 0;
  77. this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  78.   this.menuItem2,
  79.   this.menuItem3});
  80. this.menuItem1.Text = "文件(&F)";
  81. // 
  82. // menuItem2
  83. // 
  84. this.menuItem2.Index = 0;
  85. this.menuItem2.Text = "打开(&O)";
  86. this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
  87. // 
  88. // menuItem3
  89. // 
  90. this.menuItem3.Index = 1;
  91. this.menuItem3.Text = "退出(&E)";
  92. this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
  93. // 
  94. // menuItem4
  95. // 
  96. this.menuItem4.Index = 1;
  97. this.menuItem4.MdiList = true;
  98. this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  99.   this.menuItem5,
  100.   this.menuItem6,
  101.   this.menuItem7});
  102. this.menuItem4.Text = "窗口(&W)";
  103. // 
  104. // menuItem5
  105. // 
  106. this.menuItem5.Index = 0;
  107. this.menuItem5.Text = "层叠窗口(&C)";
  108. this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
  109. // 
  110. // menuItem6
  111. // 
  112. this.menuItem6.Index = 1;
  113. this.menuItem6.Text = "水平平铺窗口(&H)";
  114. this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
  115. // 
  116. // menuItem7
  117. // 
  118. this.menuItem7.Index = 2;
  119. this.menuItem7.Text = "垂直平铺窗口(&V)";
  120. this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
  121. // 
  122. // Form1
  123. // 
  124. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  125. this.ClientSize = new System.Drawing.Size(680, 353);
  126. this.IsMdiContainer = true;
  127. this.Menu = this.mainMenu1;
  128. this.Name = "Form1";
  129. this.Text = "图片浏览器";
  130. }
  131. #endregion
  132. /// <summary>
  133. /// 应用程序的主入口点。
  134. /// </summary>
  135. [STAThread]
  136. static void Main() 
  137. {
  138. Application.Run(new Form1());
  139. }
  140. private void menuItem2_Click(object sender, System.EventArgs e)
  141. {
  142. //设置文件类型过滤器 
  143. this.openFileDialog1.Filter="Image files (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif;*.tiff;*.png" 
  144. + "|JPeg files (*.jpg;*.jpeg)|*.jpg;*.jpeg" 
  145. + "|GIF files (*.gif)|*.gif" 
  146. + "|BMP files (*.bmp)|*.bmp" 
  147. + "|Tiff files (*.tif;*.tiff)|*.tif;*.tiff" 
  148. + "|Png files (*.png)|*.png" 
  149. + "|All files (*.*)|*.*";
  150. if (this.openFileDialog1.ShowDialog()==DialogResult.OK)
  151. {
  152. //获取文件的详细路径
  153. string sFileName=this.openFileDialog1.FileName;
  154. //获得文件名
  155. Form2 fm=new Form2();
  156. //将文件名数据传给子窗体
  157. fm.fileName=sFileName;
  158. //定义此窗体的父窗体,从而此窗体成为一个MDI窗体 
  159. fm.MdiParent=this;
  160. fm.Show();
  161.      }
  162. }
  163. private void menuItem3_Click(object sender, System.EventArgs e)
  164. {
  165. if (MessageBox.Show("您确定要退出吗?","提示",MessageBoxButtons.OKCancel)
  166. ==DialogResult.OK)
  167. {
  168. this.Close();
  169. Application.Exit();
  170. }
  171. else
  172. {
  173. //表示不进行任何处理
  174. }
  175. }
  176. private void menuItem5_Click(object sender, System.EventArgs e)
  177. {
  178. //层叠显示所有子窗口
  179. this.LayoutMdi(MdiLayout.Cascade);
  180. }
  181. private void menuItem6_Click(object sender, System.EventArgs e)
  182. {
  183. //水平平铺所有窗口
  184. this.LayoutMdi(MdiLayout.TileHorizontal);
  185. }
  186. private void menuItem7_Click(object sender, System.EventArgs e)
  187. {
  188. //垂直平铺所有窗口
  189. this.LayoutMdi(MdiLayout.TileVertical);
  190. }
  191. }
  192. }