如何确定winform所在的监视器?

我一直在这个网站上下,发现了很多关于Screen类的信息,以及如何计算监视器的数量等,但我如何确定一个表单目前在哪个监视器?

比使用边界更简单的方法是使用Screen.FromControl()方法。 这与Windows使用的function相同。

Screen.FromControl(this) 

将返回包含您调用它的大部分表单的屏幕的屏幕对象。

这应该是你的诀窍:

 private Screen FindCurrentMonitor(Form form) { return Windows.Forms.Screen.FromRectangle(new Rectangle( _ form.Location, form.Size)); } 

它将返回其中包含大部分表单的屏幕。 Alternativley,你可以使用

 return Windows.Forms.Screen.FromPoint(Form.Location); 

返回窗体左上角的屏幕。

我确实注意到了,但是我希望有更多的东西(来自.net而不是来自你。)所以基于你的建议,我这样做了:

  foreach (Screen screen in System.Windows.Forms.Screen.AllScreens) { if (screen.Bounds.Contains(this.Location)) { this.textBox1.Text = screen.DeviceName; } } 

每个Screen对象都有一个Bounds属性,您可以使用它来查找屏幕占用的坐标,只需检查表单的位置。