protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                case WM_ERASEBKGND:
                    return;

                case (int)WinApi.Messages.WM_NCPAINT:
                    NCPaint(ref m);
                    return;

                case WM_PAINT:
                    PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                    IntPtr      screenHdc   = BeginPaint(m.HWnd, ref paintStruct);

                    using (Graphics screenGraphics = Graphics.FromHdc(screenHdc))
                    {
                        Rectangle clipRect = new Rectangle(paintStruct.rcPaint.left,
                                                           paintStruct.rcPaint.top,
                                                           paintStruct.rcPaint.right - paintStruct.rcPaint.left,
                                                           paintStruct.rcPaint.bottom - paintStruct.rcPaint.top);

                        int width  = (mdiClient.ClientRectangle.Width > 0 ? mdiClient.ClientRectangle.Width : 0);
                        int height = (mdiClient.ClientRectangle.Height > 0 ? mdiClient.ClientRectangle.Height : 0);

                        using (Image i = new Bitmap(width, height))
                        {
                            using (Graphics g = Graphics.FromImage(i))
                            {
                                IntPtr  hdc = g.GetHdc();
                                Message printClientMessage = Message.Create(m.HWnd, WM_PRINTCLIENT, hdc, IntPtr.Zero);
                                DefWndProc(ref printClientMessage);
                                g.ReleaseHdc(hdc);

                                OnPaint(new PaintEventArgs(g, clipRect));
                            }

                            screenGraphics.DrawImage(i, mdiClient.ClientRectangle);
                        }
                    }

                    EndPaint(m.HWnd, ref paintStruct);
                    return;

                case WM_SIZE:
                    mdiClient.Invalidate();
                    break;

                case WM_NCCALCSIZE:
                    NCCalcSize(ref m);
                    return;
                }

                if (m.Msg == (int)WM_FORM_ACTIVE_CHANGED)
                {
                    OnUpdateMDITabsState(m.WParam);
                }

                base.WndProc(ref m);
            }
Ejemplo n.º 2
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case NativeWindowCommon.WM_VSCROLL:
            case NativeWindowCommon.WM_HSCROLL:
                //keep all FitToMDI children at location 0,0 even after scroll
                foreach (var item in mdiClient.MdiChildren)
                {
                    TagData tagData = item.Tag as TagData;
                    if (tagData != null && (tagData.WindowType == WindowType.FitToMdi || tagData.IsMDIClientForm))
                    {
                        item.Location = new Point();
                    }
                }
                mdiClient.Invalidate();
                break;

            case NativeWindowCommon.WM_PAINT:
                using (Graphics gr = Graphics.FromHwnd(mdiClient.Handle))
                {
                    //Paint the mdiClient its children, background image, border etc.
                    ControlRenderer.PaintMgPanel(mdiClient, gr);
                    NativeWindowCommon.ValidateRect(mdiClient.Handle, IntPtr.Zero);
                }
                return;

            default:
                break;
            }
            base.WndProc(ref m);
        }
 private void MdiForm_SizeChanged(object sender, EventArgs e)
 {
     if (_background_cache != null)
     {
         _background_cache.Dispose();
     }
     _background_cache = null;
     if (_mdi_client != null)
     {
         _mdi_client.Invalidate();
     }
 }
Ejemplo n.º 4
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            //Do all painting in WM_PAINT to reduce flicker.
            case (int)Win32.Msgs.WM_ERASEBKGND:
                return;

            case (int)Win32.Msgs.WM_PAINT:

                // This code is influenced by Steve McMahon's article:
                // "Painting in the MDI Client Area".
                // http://vbaccelerator.com/article.asp?id=4306

                // Use Win32 to get a Graphics object.
                Win32.PAINTSTRUCT paintStruct = new Win32.PAINTSTRUCT();
                IntPtr            screenHdc   = User32.BeginPaint(m.HWnd, ref paintStruct);

                using (Graphics screenGraphics = Graphics.FromHdc(screenHdc))
                {
                    // Get the area to be updated.
                    Rectangle clipRect = paintStruct.rcPaint;

                    // Double-buffer by painting everything to an image and
                    // then drawing the image.
                    int width  = (MdiClient.ClientRectangle.Width > 0 ? MdiClient.ClientRectangle.Width : 0);
                    int height = (MdiClient.ClientRectangle.Height > 0 ? MdiClient.ClientRectangle.Height : 0);
                    if (width > 0 && height > 0)
                    {
                        using (Image i = new Bitmap(width, height))
                        {
                            using (Graphics g = Graphics.FromImage(i))
                            {
                                // This code comes from J Young's article:
                                // "Generating missing Paint event for TreeView and ListView".
                                // http://www.codeproject.com/cs/miscctrl/genmissingpaintevent.asp

                                // Draw base graphics and raise the base Paint event.
                                IntPtr  hdc = g.GetHdc();
                                Message printClientMessage = Message.Create(m.HWnd, (int)Win32.Msgs.WM_PRINTCLIENT, hdc, IntPtr.Zero);
                                DefWndProc(ref printClientMessage);
                                g.ReleaseHdc(hdc);

                                // Draw the image here.
                                if (Image != null)
                                {
                                    DrawImage(g, clipRect);
                                }

                                // Call our OnPaint here to draw graphics over the
                                // original and raise our Paint event.
                                OnPaint(new PaintEventArgs(g, clipRect));
                            }

                            // Now draw all the graphics at once.
                            screenGraphics.DrawImage(i, MdiClient.ClientRectangle);
                        }
                    }
                }

                User32.EndPaint(m.HWnd, ref paintStruct);
                return;

            case (int)Win32.Msgs.WM_SIZE:
                // Repaint on every resize.
                MdiClient.Invalidate();
                break;


            case (int)Win32.Msgs.WM_NCCALCSIZE:
                // If AutoScroll is set to false, hide the scrollbars when the control
                // calculates its non-client area.
                if (!AutoScroll)
                {
                    User32.ShowScrollBar(m.HWnd, (int)Win32.ScrollBars.SB_BOTH, 0 /*false*/);
                }
                break;
            }

            base.WndProc(ref m);
        }
Ejemplo n.º 5
0
 private void MdiClient_Resize(object sender, EventArgs e)
 {
     mdiClient.Invalidate();
 }