程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> CRectTracker C#實現橡皮區矩形(2)

CRectTracker C#實現橡皮區矩形(2)

編輯:關於C語言
應的在VIEW類裡面

public class CReportVIEw : System.Windows.Forms.Form
{
   ...
   private void InitializeComponent()
   {
  ...
  this.MouseDown +=
  new System.Windows.Forms.MouseEventHandler(this.CReportVIEw_MouseDown);
  this.Paint +=
  new System.Windows.Forms.PaintEventHandler(this.PaintHandler);
  // 因為C#中不支持OnSetCursor所以只好用MouseMove替代了,
  // 各位兄台還有更好的方法,請告之
  this.MouseMove+=new MouseEventHandler(CReportVIEw_MouseMove);
   }
   private void PaintHandler(Object sender, PaintEventArgs e)
   {
  Graphics gs=e.Graphics;
  //其余的畫圖代碼
  myDoc.m_tracker.OnDraw(gs);
   }
   private void CReportVIEw_MouseDown(object sender,
                  MouseEventArgs e)
   {
   if(e.Button==MouseButtons .Left)
   {
  Rectangle rectSave=new Rectangle();
  Point pt=new Point(e.X,e.Y);
  myDoc.m_tracker.GetTrueRect(ref rectSave);
  if (myDoc.m_tracker.HitTest(pt) < 0)
  { // just to demonstrate CRectTracker::TrackRubberBand
    CRectTracker tracker=new CRectTracker();
    if (tracker.TrackRubberBand(this,
                  pt,
          myDoc.m_bAllowInvert))
    {  // see if rubber band intersects with the doc''s tracker
      tracker.NormalizeRect(ref tracker.m_rect);
      // so intersect rect works
      if (tracker.m_rect.IntersectsWith(myDoc.m_tracker.m_rect))
      { // if so, put resize handles on it (IE. select it)
        if ((myDoc.m_tracker.m_nStyle &
           CRectTracker.StyleFlags.resizeInside)!=0)
        {  // swap from resize inside to
          // resize outside for effect
          myDoc.m_tracker.m_nStyle &=
          ~CRectTracker.StyleFlags.resizeInside;
          myDoc.m_tracker.m_nStyle |=
          CRectTracker.StyleFlags.resizeOutside;
        }
        else
        {// just use inside resize handles on first time
          myDoc.m_tracker.m_nStyle &=
           ~CRectTracker.StyleFlags.resizeOutside;
          myDoc.m_tracker.m_nStyle |=
             CRectTracker.StyleFlags.resizeInside;
        }
      }
    }
    myDoc.UpdateAllVIEws(null);
     }
  }
  else
  {
    if (myDoc.m_tracker.Track(this,
     pt,
       myDoc.m_bAllowInvert,null))
    { 
    // normal tracking action, when tracker is "hit"
    myDoc.UpdateAllVIEws(null);
    }
  }
   }
   private void CReportVIEw_MouseMove(object sender, MouseEventArgs e)
   {
  Point mousept=new Point(e.X,e.Y);
  if(!myDoc.m_tracker.SetCursor(this,0,mousept))
  this.Cursor=Cursors.Arrow;
   }
   ...
}

結束。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved