如何显示在相对控制在父窗口的位置的模态形式(揭幕战) [英] How to display a Modal form in a position relative to the a control in the parent window (opener)

查看:134
本文介绍了如何显示在相对控制在父窗口的位置的模态形式(揭幕战)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有我打开使用一种形式:

Well, I have a form that I open using:

ShowDialog(this);



我尝试使用,以改变窗体的位置及其位置属性,但我不明白到底什么是相对这个位置吗?我想开低于某个按钮,这个表单。那么,如何才能做到这一点?

I try to change the position of the form using its Location property, but I don't understand what exactly is this position relative to? I want to open this form below a certain button. So how can this be done?

感谢。

推荐答案

一个形式将期望的坐标相对于屏幕的左上角。然而,控制的的范围内位置的形式与形式

A Form will expect the co-ordinates relative to the screen’s top-left corner. However, the location of a Control within a Form is relative to the top-left corner of the form.

使用该控件的位置属性来找到它的位置,然后调用 PointToScreen 在表单对象中把它变成屏幕坐标。然后你可以相对于新的形式定位

Use the Control’s Location property to find its location, and then call PointToScreen on the Form object to turn it into screen co-ordinates. Then you can position the new form relative to that.

例如:

var locationInForm = myControl.Location;
var locationOnScreen = mainForm.PointToScreen(locationInForm);

using (var model = new ModelForm())
{
    model.Location = new Point(locationOnScreen.X, locationOnScreen.Y + myControl.Height + 3);
    model.ShowDialog();
}






其实形式的客户区的左上角。

这篇关于如何显示在相对控制在父窗口的位置的模态形式(揭幕战)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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