当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
1万+





