如何获取Windows窗体在屏幕上的位置? [英] How to get the position of a Windows Form on the screen?

查看:604
本文介绍了如何获取Windows窗体在屏幕上的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio C#2010中编码WinForms应用程序,我想找出WinForm窗口左上角的位置(窗口的起始位置).

I am coding a WinForms application in Visual Studio C# 2010 and I want to find out the location of the upper left corner of the WinForm window (the starting location of the window).

我该怎么办?

推荐答案

如果您是从表单本身内部访问的,则可以编写

If you are accessing it from within the form itself then you can write

int windowHeight = this.Height;
int windowWidth = this.Width;

获取窗口的宽度和高度.还有

to get the width and height of the window. And

int windowTop = this.Top; 
int windowLeft = this.Left;

获取屏幕位置.

否则,如果您启动表单并从另一个表单访问它

Otherwise, if you launch the form and are accessing it from another form

int w, h, t, l;
using (Form form = new Form())
{
    form.Show();
    w = form.Width;
    h = form.Height;
    t = form.Top;
    l = form.Left;
}

我希望这会有所帮助.

这篇关于如何获取Windows窗体在屏幕上的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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