最近在找怎么不让子窗体超过MdiParent范围,但是一直没有找到好的方法。
最后找了个折中的办法,都是禁止那丑陋的滚动条出现的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | private const int SB_BOTH = 3; private const int WM_NCCALCSIZE = 0x83; [System.Runtime.InteropServices.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); } base.WndProc(ref m); } MdiClient mdiClient = null; private void FormMain_Load(object sender, EventArgs e) { foreach (Control c in this.Controls) { if (c is MdiClient) { mdiClient = c as MdiClient; } } } |