CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

谁能告诉我下面这段程序的执行过程,并有什么办法做个按钮,点击能使界面图片清空??

楼主kingvia(lala)2005-06-03 15:54:03 在 .NET技术 / C# 提问

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
  using   GDI_画图_四_;  
   
  namespace   DrawPictureString  
  {  
  ///   <summary>  
  ///   显示图片和文字。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.Button   button1;  
  private   System.Windows.Forms.OpenFileDialog   openFileDialog1;  
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  public   Form1()  
  {  
  //   Windows   窗体设计器支持所必需的  
  InitializeComponent();  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   Form   Designer   generated   code  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.button1   =   new   System.Windows.Forms.Button();  
  this.openFileDialog1   =   new   System.Windows.Forms.OpenFileDialog();  
  this.SuspendLayout();  
  //    
  //   button1  
  //    
  this.button1.Location   =   new   System.Drawing.Point(360,   296);  
  this.button1.Name   =   "button1";  
  this.button1.TabIndex   =   0;  
  this.button1.Text   =   "打开";  
  this.button1.TextAlign   =   System.Drawing.ContentAlignment.TopCenter;  
  this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(8,   18);  
  this.ClientSize   =   new   System.Drawing.Size(440,   328);  
  this.Controls.AddRange(new   System.Windows.Forms.Control[]   {  
      this.button1});  
  this.FormBorderStyle   =   System.Windows.Forms.FormBorderStyle.FixedDialog;  
  this.MaximizeBox   =   false;  
  this.Name   =   "Form1";  
  this.StartPosition   =   System.Windows.Forms.FormStartPosition.CenterScreen;  
  this.Text   =   "显示图片以及文字";  
  this.Paint   +=   new   System.Windows.Forms.PaintEventHandler(this.Form1_Paint);  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
  public   string   m_FileName;  
  public   Image   m_Image;  
  public   bool   m_Init   =   false;  
  //   打开图片文件。  
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  openFileDialog1.Filter   =   "图形文件(*.bmp;*.jpg;*.jpeg)|*.bmp;*.jpg;*.jpeg";  
  openFileDialog1.FilterIndex   =   1;  
  if(openFileDialog1.ShowDialog()   ==   DialogResult.OK)  
  {  
   
  m_FileName   =   openFileDialog1.FileName;  
  m_Image   =   Image.FromFile(openFileDialog1.FileName);  
  m_Init   =   true;  
  this.Validate();  
  }  
  }  
  //   处理窗体显示事件。  
  private   void   Form1_Paint(object   sender,   System.Windows.Forms.PaintEventArgs   e)  
  {  
  if(m_Init)  
  {  
  Rectangle   rect   =   new   Rectangle(0,0,this.ClientRectangle.Width,  
  this.ClientRectangle.Height-button1.Height-20);  
  Graphics   g   =   e.Graphics;  
  //   显示图片。  
  g.DrawImage(m_Image,   rect);  
  //   显示图片对应文件名信息。  
  SolidBrush   redBrush   =   new   SolidBrush(Color.Red);  
  g.DrawString(m_FileName,   new   Font("宋体",   10),   redBrush,  
  new   Point(0,this.ClientRectangle.Height-40),   StringFormat.GenericDefault);  
  }  
  }  
  }  
  }  
  问题点数:0、回复次数:2Top

1 楼vniper(爱国不爱党!)回复于 2005-06-03 16:23:43 得分 0

m_Image.Dispose();  
  this.Refresh();  
  ?Top

2 楼kingvia(lala)回复于 2005-06-06 09:35:42 得分 0

可不可以跟我说一下,这段程序整个执行过程,那个paint事件是在不断刷新的吗?Top

相关问题

  • 请问怎么使SDI没有最大化按钮和最小化按钮,而且运行程序应该为最大化界面
  • 如何在别人的应用程序上界面上加上一个按钮并响应这个按钮?最多只能给20分,还请见凉
  • 请问,那里有比较好看的按钮图标,我想把程序界面中的增加,删除,取消,打印这些按钮弄得好看点?
  • 怎样用程序清空回收站?
  • 用程序清空目录的问题
  • 我做了一個類似VC++那樣界面的程序,現在我想讓主視圖區(也就是VC++裡顯示程序源代碼的那個主窗口)在調用新建時就清空裡面的內容!
  • 美化程序界面!
  • 应用程序界面.
  • 程序界面风格
  • 为什么在程序登陆界面中输入用户名和密码时,点确定按钮时总是显示“无法获得连接句柄!"”

关键词

  • openfiledialog
  • 图片
  • button
  • clientrectangle
  • dispose
  • paint
  • 显示
  • forms
  • drawing
  • initializecomponent

得分解答快速导航

  • 帖主:kingvia

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo