如题,想让该窗体不可以最大化 该窗体为无边框的 可以改变大小的功能都已经实现 现在点中窗体的标题部分(自己做的假标题,只是为了能移动窗体),向上移动到最上边,该窗体就会变大,布局也乱了,有什么办法可以让该窗体不能最大化而且不影响改变大小的代码呢?
说白了点就是最好能让窗体在点中标题拖动到屏幕最上边的时候不最大化 ResizeMode=Norisize;可以实现但是却改变不了大小了
下边是改变窗体大小的代码
#region 配合改变窗口大小的枚举
//写在当前项目的命名空间中即可
public enum HitTest : int
{
HTERROR = -2,
HTTRANSPARENT = -1,
HTNOWHERE = 0,
HTCLIENT = 1,
HTCAPTION = 2,
HTSYSMENU = 3,
HTGROWBOX = 4,
HTMENU = 5,
HTHSCROLL = 6,
HTVSCROLL = 7,
HTMINBUTTON = 8,
HTMAXBUTTON = 9,
HTLEFT = 10,
HTRIGHT = 11,
HTTOP = 12,
HTTOPLEFT = 13,
HTTOPRIGHT = 14,
HTBOTTOM = 15,
HTBOTTOMLEFT = 16,
HTBOTTOMRIGHT = 17,
HTBORDER = 18,
HTOBJECT = 19,
HTCLOSE = 20,
HTHELP = 21,
}
#endregion
#region 改变窗体大小
//写入Class中
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
if (hwndSource != null)
{
hwndSource.AddHook(new HwndSourceHook(this.WndProc));
}
}
private const int WM_NCHITTEST = 0x0084;
private readonly int agWidth = 12; //拐角宽度
private readonly int bThickness = 6; // 边框宽度
private Point mousePoint = new Point(); //鼠标坐标
protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_NCHITTEST:
this.mousePoint.X = (lParam.ToInt32() & 0xFFFF);
this.mousePoint.Y = (lParam.ToInt32() >> 16);
#region 测试鼠标位置
// 窗口左上角
if (this.mousePoint.Y - this.Top <= this.agWidth
&& this.mousePoint.X - this.Left <= this.agWidth)
{
handled = true;
return new IntPtr((int)HitTest.HTTOPLEFT);