MSDB.UIFramwork學習劄記(二)

來源:互聯網
上載者:User
根據個人的學習習慣將UIFramwork分成了前面的幾個部分,今天來學習Image Elements 功能塊。首先從基礎類UIElements開始。
UIElements 是一個抽象類別是所有其他Image Unit類的基礎。我嘗試從UIElments類的構成來還原作者的設計思路。UIElements由五大塊構成,分別是:
事件對象
    在事件對象的定義中,作者定義了 
        public event MouseEventHandler MouseMove;  //Mouse Move事件
        public event MouseEventHandler MouseDown; //Mouse Down事件
        public event MouseEventHandler MouseUp; //Mouse Up事件
        public event EventHandler Click; //Click事件
        public event EventHandler Invalidate; //Invalidate事件 ,使繪圖區無效以達到及時重新整理繪圖層的目的
      以上五類事件是從各類Image Unit(待繪對象)的事件中抽取出來的通用事件。每個待繪對象都需要處理這五大類事件。
公用欄位

        private byte opacity;   //透明繪圖處理
        private bool visible;   //可視化處理
        private string name;

        protected int height;
        protected int width;
        protected int left;
        protected int top;

        private Color foreground;
        private Color background;

        private UIElement parent;

       待繪對象的通用屬性抽取。。
建構函式
       建構函式處理不做贅述,其中,作者將byte opacity 設定成255的值,以方便後續進行不透明處理
屬性
      屬性部分對欄位進行get set 方法處理,其中需要對三個屬性進行說明:
        public Rectangle Rectangle   //返回Elment 對象的地區範圍。由left、top、width、height屬性來確定。
        public Color Foreground     //在進行前景色彩和背景色的屬性設定中,作者在set方法中加入了OnInvalidate()方法,使用此方法可以是在設定Elements的
        public Color Background   //Foreground和Background屬性時可以達到及時重新整理的效果。
方法
      public bool HitTest(Point point);
       HitTest方法可以提供判斷待繪對象所屬範圍。從而協助處理待繪對象的滑鼠事件。
     protected virtual void OnRender(Graphics graphics);
        定義OnRender虛方法提供UIElements的繼承類自身呈現特色的方法實現。
     public void OnInvalidate()和 public void OnInvalidate(UIElement element)方法
         OnInvalidate都是使地區無效的處理,作者在此重寫了這個方法,OnInvalidate()方法 用來處理UIElement自身的Invalidate事件。OnInvalidate(UIElement element)方法用來處理繼承自UIElement的類的Invalidate事件。
     OnClick(EventArgs),OnMouseMove(MouseEventArgs),OnMouseUp(MouseEventArgs),OnMouseDown(MouseEventArgs)
        這一系列的方法通過傳遞主介面的事件參數來處理待繪對象自身特有的各類事件處理。

      以上是本人對UIElement類的總結,從這個類的構成學習可以看到作者物件導向技術的嫻熟,可以作為我們做其他的物件導向技術應用開發的很好的一個參照案例。也許內容過於簡單,大家權當再複習一遍物件導向的入門吧 :)
  PS:對於OnInvalidate方法我不知道我的描述是否正確,請大家指教!
      

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.