[英]How to easily find screen location of form Location in multi-monitor environment?
在多监视器环境中运行的C#winform应用程序(桌面跨2或3个监视器),Form的Location属性表示表单在跨区桌面上的位置,而不是物理屏幕上表单的位置。 是否有一种简单的方法可以在屏幕坐标中找到表单的位置,以获取表单所在的屏幕? 因此,如果表单位于第2或第3个显示的左上角,则位置为(0,0)?
/// <summary>Returns the location of the form relative to the top-left corner
/// of the screen that contains the top-left corner of the form, or null if the
/// top-left corner of the form is off-screen.</summary>
public Point? GetLocationWithinScreen(Form form)
{
foreach (Screen screen in Screen.AllScreens)
if (screen.Bounds.Contains(form.Location))
return new Point(form.Location.X - screen.Bounds.Left,
form.Location.Y - screen.Bounds.Top);
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.