去除MDI窗體的滾動條

 當MDI窗體的子窗體拖動超出父窗體邊界時,那個醜陋難看的滾動條就會出現,今天網上搜了好久終於找到去掉的辦法了。下面把代碼貼出來。

 

代碼來源:http://bbs.bc-cn.net/thread-167888-1-11.html

 

C#代碼:

 

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;

        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 form = new Form2();

            form.MdiParent = this;

            form.Show();

        }

 

VB.Net代碼:

 

Imports System.Runtime.InteropServices

Public Class Form1

    Dim mdiClient As MdiClient = Nothing
    Dim SB_BOTH As Integer = 3

     _
    Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Integer) As Integer
    End Function

    Protected Overrides Sub WndProc(ByRef m As Message)
        If mdiClient IsNot Nothing Then
            ShowScrollBar(mdiClient.Handle, SB_BOTH, 0)
        End If

        MyBase.WndProc(m)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For Each c As Control In Me.Controls
            If TypeOf c Is MdiClient Then
                mdiClient = c
            End If
        Next

        '測試加載一個子窗體看看
        Dim fm As Form = New Form2
        fm.MdiParent = Me
        fm.Show()

    End Sub
End Class

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章