我从配置文件加载窗口最后位置的位置(不必知道我为什么这样做而不使用应用程序设置)。读入的值是正确的,并发送到SetWindowPos P / Invoke函数。但是,从SetWindowPos返回时,值已更改。
以下是获取X Y位置并调用SetWindowPos
的代码private void LoadSettings()
{
if (File.Exists(GetSettingsPath()))
{
string p = GetSettingsPath();
FileStream fs = null;
StreamReader sr = null;
try
{
fs = new FileStream(p, FileMode.Open, FileAccess.Read, FileShare.Read);
sr = new StreamReader(fs);
XPos = int.Parse(sr.ReadLine());
YPos = int.Parse(sr.ReadLine());
thisWidth = int.Parse(sr.ReadLine());
thisHeight = int.Parse(sr.ReadLine());
// Now throw the window to back and prevent it interacting.
SetWindowPos(Handle, HWND_BOTTOM, XPos, YPos, thisWidth, thisHeight, SWP_NOMOVE | SWP_NOSIZE | SWP_NOREPOSITION | SWP_NOACTIVATE); // Set Form1 as BottomMost
sr.Close();
fs.Close();
}
catch (Exception)
{
if (sr != null) sr.Close();
if (fs != null) fs.Close();
}
}
else
{
SaveDefaultSettings();
}
}
这是P / Invoke定义:
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOACTIVATE = 0x0010;
const UInt32 SWP_NOREPOSITION = 0x0200;
private int XPos = 0;
private int YPos = 0;
private int thisWidth = 0;
private int thisHeight = 0;
显然,XPos,YPos,thisWidth和thisHeight不是SetWindoPos的一部分,但是因为它们被使用了。
所以问题:
答案 0 :(得分:0)
窗口是否定义了最小尺寸?