2011-04-23 60 views
1

WinForms中有沒有關於繪製循環的文檔?WinForms繪畫循環文檔?

當我在Windows AM程序油漆週期通常的形式:

sent a WM_PAINT message 
{ 
    call BeginPaint(&paintStruct) 

     //BeginPaint sends WM_NCPAINT and WM_ERASEBKGND 
     sent a WM_ERASEBKGND message 
     { 
     i can: 
      - allow default processing (Windows will fill the area with the default background color (e.g. white) 
      - erase and background myself (e.g. a gradient) and prevent default processing 
      - do nothing (letting whatever was there before me stay there) and prevent default processing 
     } 

    perform whatever painting i desire on 
     paintStruct.hDC (Device Context) 
     paintStruct.rcPaint (Invalid Rectangle) 
    that was populated into paintStruct during BeginPaint 

    call EndPaint() 
} 

這是所有記錄在MSDN:Windows Development\Graphics and Multimedia\Windows GDI\Painting and Drawing\About Painting and Drawing

我無法找到有關的WinForms任何這樣的文件及其塗料週期。我可以隨意找到方法和具有名稱油漆在這些事件:

  • OnPaint(保護法「引發Paint事件。」)
  • OnPrint(保護法「引發Paint事件。」)
  • InvokePaint(受保護的方法 「引發爲指定的控件Paint事件」。)
  • Paint(公共事件)
  • InvokePaintBackground(受保護的方法「引發排ntBackground事件指定控件「)
  • OnPaintBackground(保護法 」繪製控件的背景「)

注意:。忽略了一個事實,沒有PaintBackground事件

是否有文檔描述這些實體之間的設計關係? WinForms中有沒有關於繪製循環的文檔?

回答

2

這是你在找什麼?

MSDN: Custom Control Painting and Rendering


OP編輯:因爲當微軟實現其下一輪環節斷裂,文件的位置是:

  • MSDN庫
    • 開發工具和語言
      • Visual Studio 2010中
        • 的Visual Studio
          • 創建基於Windows的應用程序
            • Windows窗體
              • 入門Windows窗體
                • Windows窗體控件
                  • 開發自定義Windows窗體用。控制。NET框架
                    • 自定義控件繪畫和渲染

3

它與本地Windows繪製週期沒有本質區別,.NET事件由相應的Windows消息引發。從底部開始,消息是由窗口管理器或應用程序本身調用InvalidateRect()生成的。 .NET版本是Control.Invalidate()。 Windows會跟蹤窗口的更新區域,決定是否傳遞WM_PAINT,WM_NCPAINT和WM_ERASEBKGND消息。

當ControlStyles.UserPaint樣式打開時,WM_PAINT和WM_ERASEBKGND消息由Control.WndProc()識別。它調用虛擬的OnPaint()和OnPaintBackground()方法。派生控件可以覆蓋這些方法以根據需要自定義繪畫。並且必須調用基本方法。最終到達Control.OnPaint/Background方法,它觸發Paint和PaintBackground事件以允許其他代碼自定義繪畫。

唯一的其他皺紋是雙緩衝,由DoubleBuffered屬性啓用。 Winforms爲控件創建一個位圖緩衝區並運行OnPaintBackground()和OnPaint(),傳遞從該位圖創建的Graphics對象。然後將位圖傳送到屏幕上。

+0

我們在這裏開始陷入缺乏文檔,但'UserPaint'文檔說「如果爲false,則不會引發Paint事件。」這是否意味着'Paint事件'不會引發?或者這意味着'OnPaint'方法不會被調用?我注意到'不透明'(「如果爲true,控件被繪製爲不透明並且背景未被繪製」)會對'OnPaintBackground'產生任何影響。我看到更多:'AllPaintingInWmPaint'' OptimizedDoubleBuffer'。 – 2011-04-23 15:09:22

+0

我打算接受傑森的回答。嚴格地說,我要求提供文件。雖然MSDN文檔可能非常不足,但這正是我一直在尋找的。雖然這個答案對於MSDN的補充非常有用(+1)。 – 2011-04-23 15:10:31