Form2.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 2k
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_8
  7. {
  8. /// <summary>
  9. /// Form2 的摘要说明。
  10. /// </summary>
  11. public class Form2 : System.Windows.Forms.Form
  12. {
  13. /// <summary>
  14. /// 必需的设计器变量。
  15. /// </summary>
  16. private System.ComponentModel.Container components = null;
  17.         
  18. //代表将要打开的文件名
  19. public Form2()
  20. {
  21. //
  22. // Windows 窗体设计器支持所必需的
  23. //
  24. InitializeComponent();
  25. //
  26. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  27. //
  28. }
  29. /// <summary>
  30. /// 清理所有正在使用的资源。
  31. /// </summary>
  32. protected override void Dispose( bool disposing )
  33. {
  34. if( disposing )
  35. {
  36. if(components != null)
  37. {
  38. components.Dispose();
  39. }
  40. }
  41. base.Dispose( disposing );
  42. }
  43. #region Windows Form Designer generated code
  44. /// <summary>
  45. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  46. /// 此方法的内容。
  47. /// </summary>
  48. private void InitializeComponent()
  49. {
  50. this.components = new System.ComponentModel.Container();
  51. this.Size = new System.Drawing.Size(300,300);
  52. this.Text = "Form2";
  53. }
  54. #endregion
  55. protected override void OnPaint(PaintEventArgs e)
  56. {
  57.     Graphics g=e.Graphics;
  58. if (fileName!=null)
  59. {
  60.     //从文件名获得图片信息
  61. Bitmap bm= new Bitmap(fileName);
  62.                 
  63. //去掉路径获得文件名
  64. string sShortName=fileName.Substring(fileName.LastIndexOf("\")+1);
  65.                 //将窗口的名称改为文件名
  66. this.Text=sShortName;
  67. //根据图片大小改变窗口大小
  68. this.Width=bm.Width+6;
  69. this.Height=bm.Height+25;
  70. //显示图片
  71. g.DrawImage(bm,0,0,bm.Width,bm.Height);
  72. }
  73. }
  74. /// <summary>
  75. /// 代表将要打开的文件名
  76. /// </summary>
  77. public string fileName;
  78. }
  79. }