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

RECT windowRect = new RECT();
User32.GetWindowRect(MyForm2.Handle, ref windowRect);
User32.SetWindowPos(MyForm2.Handle, 0, 0, 0, 5000, 500, 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;        
    }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2021-12-18
  • 2021-08-19
猜你喜欢
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案