资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

c#中 Invalidate函数使用问题

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

看原码,当我点击按钮时我想让指定矩形重化,其他不画,可Invalidate(rect)函数好象没起作用,不该重画的都画出来了。  
   
  using   System;  
  using   System.Drawing;  
  using   System.Drawing.Drawing2D;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
   
  namespace   WindowsApplication4  
  {  
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
  private   System.Windows.Forms.Button   button1;  
  bool   bdraw   =   false;  
  Graphics   m_gh;  
  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   窗体设计器生成的代码  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.button1   =   new   System.Windows.Forms.Button();  
  this.SuspendLayout();  
  //    
  //   button1  
  //    
  this.button1.Location   =   new   System.Drawing.Point(232,   64);  
  this.button1.Name   =   "button1";  
  this.button1.Size   =   new   System.Drawing.Size(40,   24);  
  this.button1.TabIndex   =   0;  
  this.button1.Text   =   "button1";  
  this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(292,   273);  
  this.Controls.Add(this.button1);  
  this.Name   =   "Form1";  
  this.Text   =   "Form1";  
  this.Load   +=   new   System.EventHandler(this.Form1_Load);  
  this.Paint   +=   new   System.Windows.Forms.PaintEventHandler(this.Form1_Paint);  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
  private   void   Form1_Paint(object   sender,   System.Windows.Forms.PaintEventArgs   e)  
  {  
  m_gh.DrawRectangle(Pens.Blue,10,10,10,10);  
  if   (bdraw)  
  {  
  m_gh.FillRectangle(Brushes.Red,30,30,10,10);  
  }  
  }  
   
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  bdraw   =   true;  
  //this.Invalidate();  
  Point[]   pt   =   new   Point[2];  
  pt[0]   =   new   Point(10,10);  
  pt[1]   =   new   Point(20,20);  
  m_gh.TransformPoints(CoordinateSpace.Device,CoordinateSpace.World,pt);  
   
  this.Invalidate(new   Rectangle(pt[0].X,pt[0].Y,pt[1].X-pt[0].X,pt[1].Y-pt[0].Y));  
  }  
   
  private   void   Form1_Load(object   sender,   System.EventArgs   e)  
  {  
  m_gh   =   this.CreateGraphics();  
  m_gh.PageScale   =   0.1f;  
  m_gh.PageUnit   =   GraphicsUnit.Millimeter;  
  }  
  }  
  }  
 

网友回答:

发表者:khpcg

ding


 

 
热门推荐笔记本: 清华同方笔记本
相关文章:
笔记本相关:
IT技术文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved