C# - MDI 부모창 스크롤 제거

MDI로 개발시 자식창을 부모창영역 밖으로 이동하면 부모창에 스크롤이 생기는데..
이게 거슬린다면 적용해보시기 바랍니다.

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

namespace MdiScroll
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            MyNativeWindows na = new MyNativeWindows();

            for (int i = 0; i < this.Controls.Count; i++)
            {
                MdiClient mdiClient = this.Controls[i] as MdiClient;
                if (mdiClient != null)
                {
                    na.ReleaseHandle();
                    na.AssignHandle(mdiClient.Handle);
                }
            }

            //for (int i = 0 ; i<10; i++)
            //{
            //    Form f = new Form();
            //    f.MdiParent = this;
            //    f.Show();
            //}
        }
    }

    public class MyNativeWindows : NativeWindow
    {
        public MyNativeWindows()
        {
        }

        private const int WM_NCCALCSIZE = 0x0083;
        private const int SB_BOTH = 3;

        [DllImport("user32.dll")]
        private static extern int ShowScrollBar(IntPtr hWnd, int wBar, int bShow);

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_NCCALCSIZE:
                    ShowScrollBar(m.HWnd, SB_BOTH, 0);
                    break;
            }
            base.WndProc(ref m);
        }
    }
}

 

사용자 삽입 이미지

댓글 1개

댓글 남기기