Пример #1
0
        /// <summary>Occurs when a Windows message is dispatched.</summary>
        /// <param name="message">Message to process.</param>
        /// <remarks>Overrides WM_PAINT, WM_ERASEBKGND.</remarks>
        protected override void WndProc(ref Message message)
        {
            const int WM_PAINT       = 0x000F;
            const int WM_PRINTCLIENT = 0x0318;
            const int WM_ERASEBKGND  = 0x0014;

            switch (message.Msg)
            {
            case WM_ERASEBKGND:
                //removes flicker
                return;

            case WM_PAINT:
                // The designer host does not call OnResize()
                if (internalGraphics == null)
                {
                    OnResize(EventArgs.Empty);
                }

                //Set up
                Win32.RECT updateRect = new Win32.RECT();
                if (Win32.GetUpdateRect(message.HWnd, ref updateRect, false) == 0)
                {
                    break;
                }

                Win32.PAINTSTRUCT paintStruct = new Win32.PAINTSTRUCT();
                IntPtr            screenHdc   = Win32.BeginPaint(message.HWnd, ref paintStruct);
                using (Graphics screenGraphics = Graphics.FromHdc(screenHdc))
                {
                    //Draw Internal Graphics
                    IntPtr  hdc = internalGraphics.GetHdc();
                    Message printClientMessage = Message.Create(Handle, WM_PRINTCLIENT, hdc, IntPtr.Zero);
                    DefWndProc(ref printClientMessage);
                    internalGraphics.ReleaseHdc(hdc);

                    //Add the missing OnPaint() call
                    OnPaint(new PaintEventArgs(internalGraphics, Rectangle.FromLTRB(
                                                   updateRect.left,
                                                   updateRect.top,
                                                   updateRect.right,
                                                   updateRect.bottom)));

                    //Draw Screen Graphics
                    screenGraphics.DrawImage(internalBitmap, 0, 0);
                }

                //Tear down
                Win32.EndPaint(message.HWnd, ref paintStruct);
                return;
            }
            base.WndProc(ref message);
        }
Пример #2
0
        /// <summary>Occurs when a Windows message is dispatched.</summary>
        /// <param name="message">Message to process.</param>
        /// <remarks>Overrides WM_PAINT, WM_ERASEBKGND.</remarks>
        protected override void WndProc(ref Message message)
        {
            const int WM_PAINT = 0x000F;
             const int WM_PRINTCLIENT = 0x0318;
             const int WM_ERASEBKGND = 0x0014;

             switch (message.Msg)
             {

            case WM_ERASEBKGND:
               //removes flicker
               return;

            case WM_PAINT:
               // The designer host does not call OnResize()
               if (internalGraphics == null)
                  OnResize(EventArgs.Empty);

               //Set up
               Win32.RECT updateRect = new Win32.RECT();
               if (Win32.GetUpdateRect(message.HWnd, ref updateRect, false) == 0)
                  break;

               Win32.PAINTSTRUCT paintStruct = new Win32.PAINTSTRUCT();
               IntPtr screenHdc = Win32.BeginPaint(message.HWnd, ref paintStruct);
               using (Graphics screenGraphics = Graphics.FromHdc(screenHdc))
               {

                  //Draw Internal Graphics
                  IntPtr hdc = internalGraphics.GetHdc();
                  Message printClientMessage = Message.Create(Handle, WM_PRINTCLIENT, hdc, IntPtr.Zero);
                  DefWndProc(ref printClientMessage);
                  internalGraphics.ReleaseHdc(hdc);

                  //Add the missing OnPaint() call
                  OnPaint(new PaintEventArgs(internalGraphics, Rectangle.FromLTRB(
                      updateRect.left,
                      updateRect.top,
                      updateRect.right,
                      updateRect.bottom)));

                  //Draw Screen Graphics
                  screenGraphics.DrawImage(internalBitmap, 0, 0);
               }

               //Tear down
               Win32.EndPaint(message.HWnd, ref paintStruct);
               return;
             }
             base.WndProc(ref message);
        }