位置坐标在电脑显示X = -32000,Y = -32000 [英] Location Coordinates On Computer Showing X=-32000, Y=-32000

查看:770
本文介绍了位置坐标在电脑显示X = -32000,Y = -32000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#应用程序,节省了当它被关闭的状态,然后读取保存的状态启动时。被保存的一个项目是主窗体的位置。通常这个伟大的工程 - 在我的code有这样一条线的位置保存到一个文件,然后在启动时回读:

I have a C# application that saves its state when it is closed and then reads in the saved state when it starts up. One item that is saved is the location of the main form. Normally this works great - in my code there is a line like this that saves the location to a file that is then read back in on startup:

streamWriter.WriteLine("location:" + this.Location.X + "," + this.Location.Y);

通常情况下,坐标位置是这样我的机器上使用多个显示器:

Normally, the location coordinates look like this on my machine with multiple monitors:

location:-1069,283

我偶尔会看到,保存这样的坐标:

Occasionally I'll see coordinates that are saved like this:

location:-32000,-32000

然后当用户将应用程序备份,形式离开桌面,并不能(容易)被一个普通用户检索。

And then when the user brings the app back up, the form is way off the desktop and can't (easily) be retrieved by an average user.

发生了什么事,使坐标阅读方式以及是否有建议,以prevent这种情况呢?

What is happening to make the coordinates be read this way and are there suggestions to prevent this situation?

推荐答案

你看到的坐标是由于这样的事实,当它关闭时,应用程序被最小化。 Windows的隐藏的形式通过实际移动它,从它的坐标到一些大的离谱负X,Y坐标。

The coordinates you're seeing are due to the fact that the application is minimized when it is closed. Windows "hides" your form by actually moving it from its coordinates to some ridiculously large negative X,Y coordinates.

验证编程:

这是一种形式的应用程序输出在Vista上:

Output from a form app on Vista:

当前坐标X:184 Y:184 *默认位置 当前坐标X: - 32000 Y: - 32000 *最小化位置

Current coordinates X: 184 Y: 184 *Default Location Current coordinates X: -32000 Y: -32000 *Minimized Location

从code:

System.Diagnostics.Debug.WriteLine(当前坐标X:+ Location.X +Y+ Location.Y);

System.Diagnostics.Debug.WriteLine("Current coordinates X: " + Location.X + " Y: " + Location.Y );

要解决这个问题,我会简单地检查这样的值,当你的应用程序正在关闭,而不是实际保存到文件。

To solve this i would simply check for such a value when your app is closing and not actually save it to file.

如果你不想惹做数学上任意坐标值,你也可以检查将WindowState。请参见这里MSDN

If you don't want to mess with doing math on arbitrary coordinate values you could also check the WindowState. See here on MSDN

这篇关于位置坐标在电脑显示X = -32000,Y = -32000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆