Application stuck in full screen?

前端 未结 4 1839
醉酒成梦
醉酒成梦 2020-12-08 17:01

To reproduce my problem please do the following:

  1. Create a new Windows Form Application in C#.
  2. In the Properties window of Form1 set FormBorderSt
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 17:55

    Trap the WM_GETMINMAXINFO message which will allow you to specify the maximized size and location of your form. Technically your form will still change state to Maximized, but it will appear the same since we specify the maximized size/position to be the same as the normal state of the form:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        public struct POINTAPI
        {
            public Int32 X;
            public Int32 Y;
        }
    
        public struct MINMAXINFO
        {
            public POINTAPI ptReserved;
            public POINTAPI ptMaxSize;
            public POINTAPI ptMaxPosition;
            public POINTAPI ptMinTrackSize;
            public POINTAPI ptMaxTrackSize;
        }
    
        public const Int32 WM_GETMINMAXINFO = 0x24;
    
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_GETMINMAXINFO:
                    MINMAXINFO mmi = (MINMAXINFO)System.Runtime.InteropServices.Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
                    mmi.ptMaxSize.X = this.Width;
                    mmi.ptMaxSize.Y = this.Height;
                    mmi.ptMaxPosition.X = this.Location.X;
                    mmi.ptMaxPosition.Y = this.Location.Y;
                    System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);
                    break;
            }
            base.WndProc(ref m);
        }
    
    }
    

提交回复
热议问题