【IT168技术文档】
1)使用窗体默认的最大化方法
this.WindowState = FormWindowState.Maximized 发现窗体的位置x和y都是小于零的。设置了 this.Location = new Point(1, 1);后仍然无效。。。
2)设置了窗体的最大值后,测试发现有时候(窗体宽度接近屏幕的宽度的时候),窗体的高度的设置是无效的。
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class FormRegion : Form { private const long WM_GETMINMAXINFO = 0x24; 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; } public FormRegion() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); } protected override void WndProc(ref System.Windows.Forms.Message m) { base.WndProc(ref m); if (m.Msg == WM_GETMINMAXINFO) { MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO)); mmi.ptMinTrackSize.x = this.MinimumSize.Width; mmi.ptMinTrackSize.y = this.MinimumSize.Height; if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0) { mmi.ptMaxTrackSize.x = this.MaximumSize.Width; mmi.ptMaxTrackSize.y = this.MaximumSize.Height; } mmi.ptMaxPosition.x = 1; mmi.ptMaxPosition.y = 1; System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true); } } } }