如何在固定位置将子窗体固定在父窗体中? [英] how to fix a child form in a parent form at a fixed position?

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

问题描述

在Windows应用程序中,如何将子窗体固定在父窗体的固定位置?
我们不能将该子窗体拖动到任何其他位置.

In windows Application,how we fix a child form at a fixed position in a parent form?
we cant drag that childform to any other position.

推荐答案

您当然可以将窗体添加为另一窗体的子窗体",并且只要公开TitleBar,就可以按原样"拖动:
You certainly can add a Form as a ''child form'' of another Form, and it''s draggable "as is," as long as you expose the TitleBar:
private void Form1_Load(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    f2.TopLevel = false;
    //
    f2.Parent = this;
    //
    f2.ControlBox = false;
    f2.MinimizeBox = false;
    f2.MaximizeBox = false;
    f2.ShowInTaskbar = false;
    f2.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    f2.Text = "Form2";
    f2.Show();
}


但是,请注意,在这种情况下,我们没有将第二个窗体设置为我们定义为MDIParent窗体的第一个窗体的MDIChild:因此在这种情况下,可以通过以下方式设置第二个窗体的FormStartPosition:


But, note that in this scenario we are not setting the second Form to be an MDIChild of the first Form which we have defined as an MDIParent Form: so in this case setting the FormStartPosition of the second Form by something like:

f2.FormStartPosition = FormStartPosition.CenterParent; 

Will没有效果.

通常,同时使用MDI体系结构和在Forms中使用Forms并不是一个好主意,并且MDI现在已弃用",这意味着它不被认为是一种好的,现代的体系结构.

请考虑将第二个表格归于"第一个表格所有":

Will have no effect.

In general, both using MDI architecture, and using Forms within Forms is not that good an idea, and MDI is now "deprecated," meaning not considered a good, modern, architecture.

Please think about making the second Form ''owned'' by the first Form:

private void Form1_Load(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    f2.TopLevel = true;
    //
    f2.Owner = this;
    //
    f2.StartPosition = FormStartPosition.CenterScreen;
    f2.ControlBox = false;
    f2.MinimizeBox = false;
    f2.MaximizeBox = false;
    f2.ShowInTaskbar = false;
    f2.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    f2.SizeGripStyle = SizeGripStyle.Hide;
    f2.Text = "Form2";
    f2.Show();
}

,然后看它如何为您工作.您可以轻松地为第二个Form编写一个移动事件处理程序",以将其保持在第一个Form的范围内:如果这对您的设计很重要,或者,如果启用了Form2的大小调整,则可以处理ReSize事件并根据需要使Form2出现在Form1中.

And see how this works for you. You can easily write a ''Move event handler for the second Form to keep it inside the bounds of the first Form: if that''s important to your design, or, if you enable Form2 to be resized you can handle the ReSize event and, if you wish, make Form2 appear "within" Form1.


这篇关于如何在固定位置将子窗体固定在父窗体中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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