且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取Windows窗体在屏幕上的位置?

更新时间:2023-12-06 12:42:34

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

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;
}

我希望这会有所帮助.