Form3.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 9k
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. namespace ch2_9
  7. {
  8. /// <summary>
  9. /// Form3 的摘要说明。
  10. /// </summary>
  11. public class Form3 : System.Windows.Forms.Form
  12. {
  13. private System.Windows.Forms.GroupBox groupBox1;
  14. private System.Windows.Forms.GroupBox groupBox2;
  15. private System.Windows.Forms.Label label1;
  16. private System.Windows.Forms.Button button1;
  17. private System.Windows.Forms.Button button2;
  18. //这行代码修改过
  19. public  System.Windows.Forms.ListView listView1;
  20. //这行代码修改过
  21. public  System.Windows.Forms.TextBox textBox1;
  22. private System.Windows.Forms.Button button3;
  23. private System.Windows.Forms.SaveFileDialog saveFileDialog1;
  24. /// <summary>
  25. /// 必需的设计器变量。
  26. /// </summary>
  27. private System.ComponentModel.Container components = null;
  28. public Form3()
  29. {
  30. //
  31. // Windows 窗体设计器支持所必需的
  32. //
  33. InitializeComponent();
  34. //
  35. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  36. //
  37. }
  38. /// <summary>
  39. /// 清理所有正在使用的资源。
  40. /// </summary>
  41. protected override void Dispose( bool disposing )
  42. {
  43. if( disposing )
  44. {
  45. if(components != null)
  46. {
  47. components.Dispose();
  48. }
  49. }
  50. base.Dispose( disposing );
  51. }
  52. #region Windows Form Designer generated code
  53. /// <summary>
  54. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  55. /// 此方法的内容。
  56. /// </summary>
  57. private void InitializeComponent()
  58. {
  59. System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {
  60. new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "BMP   Windows Bitmap", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))))}, -1);
  61. System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {
  62. new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "JPG   JPEG ", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))))}, -1);
  63. System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {
  64. new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "TIFF  Tag Image File Format", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))))}, -1);
  65. System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {
  66. new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "PNG   Portable Network Graphics", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))))}, -1);
  67. System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem(new System.Windows.Forms.ListViewItem.ListViewSubItem[] {
  68. new System.Windows.Forms.ListViewItem.ListViewSubItem(null, "GIF   CompuServer GIF", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))))}, -1);
  69. this.groupBox1 = new System.Windows.Forms.GroupBox();
  70. this.listView1 = new System.Windows.Forms.ListView();
  71. this.groupBox2 = new System.Windows.Forms.GroupBox();
  72. this.button3 = new System.Windows.Forms.Button();
  73. this.textBox1 = new System.Windows.Forms.TextBox();
  74. this.label1 = new System.Windows.Forms.Label();
  75. this.button1 = new System.Windows.Forms.Button();
  76. this.button2 = new System.Windows.Forms.Button();
  77. this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
  78. this.groupBox1.SuspendLayout();
  79. this.groupBox2.SuspendLayout();
  80. this.SuspendLayout();
  81. // 
  82. // groupBox1
  83. // 
  84. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  85. this.listView1});
  86. this.groupBox1.Location = new System.Drawing.Point(16, 16);
  87. this.groupBox1.Name = "groupBox1";
  88. this.groupBox1.Size = new System.Drawing.Size(320, 136);
  89. this.groupBox1.TabIndex = 0;
  90. this.groupBox1.TabStop = false;
  91. this.groupBox1.Text = "目标格式";
  92. // 
  93. // listView1
  94. // 
  95. this.listView1.FullRowSelect = true;
  96. this.listView1.HideSelection = false;
  97. this.listView1.HoverSelection = true;
  98. this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
  99.   listViewItem1,
  100.   listViewItem2,
  101.   listViewItem3,
  102.   listViewItem4,
  103.   listViewItem5});
  104. this.listView1.Location = new System.Drawing.Point(48, 24);
  105. this.listView1.Name = "listView1";
  106. this.listView1.Size = new System.Drawing.Size(248, 97);
  107. this.listView1.TabIndex = 0;
  108. this.listView1.View = System.Windows.Forms.View.List;
  109. // 
  110. // groupBox2
  111. // 
  112. this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
  113. this.button3,
  114. this.textBox1,
  115. this.label1});
  116. this.groupBox2.Location = new System.Drawing.Point(16, 168);
  117. this.groupBox2.Name = "groupBox2";
  118. this.groupBox2.Size = new System.Drawing.Size(320, 112);
  119. this.groupBox2.TabIndex = 1;
  120. this.groupBox2.TabStop = false;
  121. this.groupBox2.Text = "文件输出";
  122. // 
  123. // button3
  124. // 
  125. this.button3.Location = new System.Drawing.Point(216, 80);
  126. this.button3.Name = "button3";
  127. this.button3.TabIndex = 2;
  128. this.button3.Text = "浏览";
  129. this.button3.Click += new System.EventHandler(this.button3_Click);
  130. // 
  131. // textBox1
  132. // 
  133. this.textBox1.Location = new System.Drawing.Point(120, 40);
  134. this.textBox1.Name = "textBox1";
  135. this.textBox1.Size = new System.Drawing.Size(160, 21);
  136. this.textBox1.TabIndex = 1;
  137. this.textBox1.Text = "";
  138. // 
  139. // label1
  140. // 
  141. this.label1.Location = new System.Drawing.Point(16, 43);
  142. this.label1.Name = "label1";
  143. this.label1.Size = new System.Drawing.Size(80, 23);
  144. this.label1.TabIndex = 0;
  145. this.label1.Text = "输出文件路径";
  146. // 
  147. // button1
  148. // 
  149. this.button1.Location = new System.Drawing.Point(200, 304);
  150. this.button1.Name = "button1";
  151. this.button1.TabIndex = 2;
  152. this.button1.Text = "确定";
  153. this.button1.Click += new System.EventHandler(this.button1_Click);
  154. // 
  155. // button2
  156. // 
  157. this.button2.Location = new System.Drawing.Point(280, 304);
  158. this.button2.Name = "button2";
  159. this.button2.TabIndex = 3;
  160. this.button2.Text = "取消";
  161. this.button2.Click += new System.EventHandler(this.button2_Click);
  162. // 
  163. // saveFileDialog1
  164. // 
  165. this.saveFileDialog1.CreatePrompt = true;
  166. this.saveFileDialog1.FileName = "doc1";
  167. // 
  168. // Form3
  169. // 
  170. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  171. this.ClientSize = new System.Drawing.Size(360, 341);
  172. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  173.   this.button2,
  174.   this.button1,
  175.   this.groupBox2,
  176.   this.groupBox1});
  177. this.Name = "Form3";
  178. this.Text = "文件格式转换";
  179. this.groupBox1.ResumeLayout(false);
  180. this.groupBox2.ResumeLayout(false);
  181. this.ResumeLayout(false);
  182. }
  183. #endregion
  184. private void button1_Click(object sender, System.EventArgs e)
  185. {
  186. //检查文件名是否错误
  187. if (this.textBox1.Text=="")
  188. {
  189. MessageBox.Show("文件名填写不正确","警告",
  190. MessageBoxButtons.OK,MessageBoxIcon.Error);
  191. }
  192. //检查是否已经选定了文件格式
  193. else if(this.listView1.SelectedItems.Count==0)
  194. {
  195. MessageBox.Show("请选择保存类型","警告",
  196. MessageBoxButtons.OK,MessageBoxIcon.Error);
  197. }
  198. else
  199. {
  200. //返回DialogResult枚举,关闭窗体
  201. this.DialogResult=DialogResult.OK;
  202. this.Close();
  203. }
  204. }
  205. private void button2_Click(object sender, System.EventArgs e)
  206. {
  207. //返回DialogResult枚举,关闭窗体
  208. this.DialogResult=DialogResult.Cancel;
  209. this.Close();
  210. }
  211. private void button3_Click(object sender, System.EventArgs e)
  212. {
  213. //设置过滤器
  214. this.saveFileDialog1.Filter="Image files (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif;*.tiff;*.png" 
  215. + "|JPeg files (*.jpg;*.jpeg)|*.jpg;*.jpeg" 
  216. + "|GIF files (*.gif)|*.gif" 
  217. + "|BMP files (*.bmp)|*.bmp" 
  218. + "|Tiff files (*.tif;*.tiff)|*.tif;*.tiff" 
  219. + "|Png files (*.png)|*.png" 
  220. + "|All files (*.*)|*.*";
  221. if (this.saveFileDialog1.ShowDialog()==DialogResult.OK)
  222. {
  223. //将选定的路径写到textBox中去
  224. string fileName=this.saveFileDialog1.FileName;
  225. this.textBox1.Text=fileName;
  226. }
  227. }
  228. }
  229. }