views:

641

answers:

3

Well I just finished checking through the few related questions and one seemed to have the answer but the link is broken and the other wasnt very well stated.

I'm merely trying to remove the scrollbars on the mdi parent when a child is moved outside the parent's bounds.

What I'm trying to accomplish is to reproduce menus that can appear within mmo's that you can move around and off the screen. I assumed it was with multiple forms but if I'm wrong or I'm doing it the hard way, please correct me.

A: 

I found this which uses interop.

The link also shows how to prevent a child form from moving beyond the mdi parent's borders.

The code provided in the link does the trick, but you'll have to add the following using directive:

using System.Runtime.InteropServices;

As mentioned in the linked thread, there is a bit of a flicker but you might want to try it out.

Jay Riggs
A: 

How about something like this. You get minor flicker, but I am sure there is a workaround for that:

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        private const int SB_BOTH = 3;
        private const int WM_NCCALCSIZE = 0x83;

        [DllImport("user32.dll")]

        private static extern int ShowScrollBar(IntPtr hWnd, int wBar, int bShow);
        protected override void WndProc(ref Message m)
        {
            if (mdiClient != null)
            {
                ShowScrollBar(mdiClient.Handle, SB_BOTH, 0 /*Hide the ScrollBars*/);
            }
            base.WndProc(ref m);
        }

        MdiClient mdiClient = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (Control c in this.Controls) //Find the MdiClient in the MdiWindow
            {
                if (c is MdiClient)
                {
                    mdiClient = c as MdiClient;
                }
            }

            Form2 newChild = new Form2();
            newChild.MdiParent = this;
            newChild.Show();
        }
    }
}
Jason Heine
A: 

It is easier way to do it and without flicking. Look at this:

    protected override void WndProc(ref Message m)
    {
        if (m.Msg != 3)
        {
            base.WndProc(ref m);
        }
    }