關於c# winForm窗體最大化的設定
阿新 • • 發佈:2019-01-10
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);
}
}
}
}
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);
}
}
}
}