C# 大于屏幕的窗体

时间:2023-03-09 13:01:54
C# 大于屏幕的窗体

1.使用SetWindowPos就可以做到这一点,只是最后一个参数要选对。

RECT windowRect = new RECT();
User32.GetWindowRect(MyForm2.Handle, ref windowRect);
User32.SetWindowPos(MyForm2.Handle, , , , , , ApiConstants.SWP_NOSENDCHANGING);

2.虽然设置完后窗体的大小改变了,但如果窗体的一旦重绘又会被屏幕大小限制而缩小。所以看下面的代码:

protected override void WndProc(ref Message m)
{
const int WM_GETMINMAXINFO = 0x24;
if (m.Msg == WM_GETMINMAXINFO)
{
MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
mmi.ptMinTrackSize.x = this.Size.Width;
mmi.ptMinTrackSize.y = this.Size.Height;
Marshal.StructureToPtr(mmi, m.LParam, true);
}
base.WndProc(ref m);
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
} public struct POINTAPI
{
public int x;
public int y;
} public struct MINMAXINFO
{
public POINTAPI ptReserved;
public POINTAPI ptMaxSize;
public POINTAPI ptMaxPosition;
public POINTAPI ptMinTrackSize;
public POINTAPI ptMaxTrackSize;
}

以上代码在VS2010+Windows7Ultimate下调试通过,运行达到效果。