Question

I have a MDI Parent (Form1) and a MDI Child (Form2). I have currently disabled scroll bars for Form1 when Form2 goes past the bounds of Form1 by placing the following code within Form2:

protected override void WndProc(ref Message m)
{
    const int WM_MOVE = 0x0003;

    switch (m.Msg)
    {
        case WM_MOVE:
            return;

        default:
            base.WndProc(ref m);
            break;
    }
}

While the scroll bars for Form1 will not show if Form2 goes out of bounds when the user drags Form2 out of Form1's bounds. It will however show the scroll bars if the user resizes Form1 to where Form2 goes out of bounds.

How can I fix it so that this does not occur

Was it helpful?

Solution

I found a work-able solution for myself for now. On the MDI Form (Form1). I use the following code. It at least help's to get rid of the flickering.

    [System.Runtime.InteropServices.DllImport("user32.dll")]

    private static extern int ShowScrollBar(IntPtr hWnd, int wBar, int bShow);

    protected override void WndProc(ref Message m)
    {
        const int WM_MOVE = 0x0003;
        const int WM_ENTERSIZEMOVE = 0x0231;
        const int WM_EXITSIZEMOVE = 0x0232;
        const int SB_BOTH = 3;

        switch (m.Msg)
        {
            // Use SuspendLayout() instead of having constant flickering on resize starting
            case WM_ENTERSIZEMOVE:
                this.SuspendLayout();
                base.WndProc(ref m);
                break;

            // Do not forget to ResumeLayout() when resizing finished
            case WM_EXITSIZEMOVE:
                this.ResumeLayout();
                base.WndProc(ref m);
                break;

            default:
                ShowScrollBar(this.Handle, SB_BOTH, 0);
                base.WndProc(ref m);
                break;
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top