博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WinForm无边框窗体依据任务栏位置最大化
阅读量:4947 次
发布时间:2019-06-11

本文共 2601 字,大约阅读时间需要 8 分钟。

任务栏位置可能在上下左右,而无边框窗体最大化的时候却默认坐标为0,0.下面是解决办法:

#region 最大化处理

/*任务栏位置*/
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SystemParametersInfo(int uAction, int uParam, ref RECT re, int fuWinTni);
[System.Runtime.InteropServices.DllImport("SHELL32", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData);
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;//属性代表上、下、左、右
public RECT rc;
public IntPtr lParam;
}
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public override string ToString()
{
return "{left=" + left.ToString() + ", " + "top=" + top.ToString() + ", " +
"right=" + right.ToString() + ", " + "bottom=" + bottom.ToString() + "}";
}
}
/*窗体坐标*/
private const long WM_GETMINMAXINFO = 0x24;
private struct POINTAPI
{
public int x;
public int y;
}
private struct MINMAXINFO
{
public POINTAPI ptReserved;
public POINTAPI ptMaxSize;
public POINTAPI ptMaxPosition;
public POINTAPI ptMinTrackSize;
public POINTAPI ptMaxTrackSize;
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_GETMINMAXINFO)
{
this.MaximumSize = SystemInformation.WorkingArea.Size;
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;
}
//-------------------------
int aaa = 0x00000005;
APPBARDATA pdat = new APPBARDATA();
SHAppBarMessage(aaa, ref pdat);

if (pdat.uEdge == 0) //左

{
mmi.ptMaxPosition.x = Screen.PrimaryScreen.Bounds.Width - SystemInformation.WorkingArea.Width;
mmi.ptMaxPosition.y = 0;
}
else if (pdat.uEdge == 1) //上
{
mmi.ptMaxPosition.x = 0;
mmi.ptMaxPosition.y = Screen.PrimaryScreen.Bounds.Height - SystemInformation.WorkingArea.Height;
}
else if (pdat.uEdge == 2) //右
{
mmi.ptMaxPosition.x = 0;
mmi.ptMaxPosition.y =0;
}
else if (pdat.uEdge == 3) //下
{
mmi.ptMaxPosition.x = 0;
mmi.ptMaxPosition.y = 0;
}

System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);

}
}
#endregion

转载于:https://www.cnblogs.com/lihoo/p/5786525.html

你可能感兴趣的文章
收藏夹(持续更新)
查看>>
iOS中的#import和class区别
查看>>
节约内存,请使用标签页管理工具:onetab、better onetab
查看>>
jQuery中的事件与动画
查看>>
页面加载骨架
查看>>
关于android系统不关屏设置
查看>>
SONY VPCS138EC降级安装XP
查看>>
[luogu4201][bzoj1063]设计路线【树形DP】
查看>>
手机抓包-手机劫持域名到指定服务器
查看>>
被放逐的皇后 金建云
查看>>
Javascript 有用参考函数
查看>>
点群的判别(三)
查看>>
gradle
查看>>
GNSS 使用DFT算法 能量损耗仿真
查看>>
常见的控制跳转的宏定义
查看>>
JavaSE| 面向对象的三大特征
查看>>
tensorflow Tensorboard可视化-【老鱼学tensorflow】
查看>>
eigen主页
查看>>
暑假周进度报告1
查看>>
兔子数
查看>>