Windows.Forms Visual Studio,如何直接在第一个窗口上打开第二个窗口? [英] Windows.Forms Visual Studio, How to open a second window directly over the first window?

查看:88
本文介绍了Windows.Forms Visual Studio,如何直接在第一个窗口上打开第二个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在第一个窗口的正上方打开第二个窗口,而不是在默认位置稍微向右下方或向后打开?我只是想制作一些可以点击的屏幕.我还有其他方法可以这样做吗?

How can I open a second window directly over the first, and not slightly diagonally down-right or back at the default position? I'm just trying to make a few screens to be clicked through. Is there another way I should be doing this?

CenterParent 为什么不这样做?那么 CenterParent 会做什么?

why doesnt CenterParent do it? What does CenterParent do then?

推荐答案

尝试将新表单的位置设置为与第一个现有表单相同.确保第二个表单的 StartPosition 属性设置为手动".这假设您的表单都是相同尺寸.

Try setting the location of the new form to be equal to the first, existing form. Make sure that the second form's StartPosition property is set to 'Manual'. This assumes your forms are all the same sizes.

浮动"形式的示例构造函数:

Example constructor of the 'floating' form:

// reference to the form underneath, as it might
// change location between creating the FloatingWindow, and showing
// FloatingWindow!
Form BeneathWindow;

public FloatingWindow(Form BeneathWindow)
{
   InitializeComponent();

   // save this for when we show the form
   this.BeneathWindow = BeneathWindow;
   StartPosition = FormStartPosition.Manual;

}

// OnLoad event handler
private void FloatingWindowLoad(object sender, EventArgs e)
{
   Location = BeneathWindow.Location;
}

如果您的表单大小不同,那么您可能希望将它们居中.您可以按照其他人的建议使用 CenterParent,也可以自己手动将它们居中,就像我有时喜欢做的那样:

If your forms are not the same sizes, then you'll likely want to center them. You can use CenterParent as others have suggested, or you can manually center them yourself, as I sometimes like to do:

Location = new Point((BeneathWindow.Width - Width)/2 , (BeneathWindow.Height - Height)/2 );

两者都应该可行!

这篇关于Windows.Forms Visual Studio,如何直接在第一个窗口上打开第二个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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