如何在固定位置将子窗体固定在父窗体中?

编程入门 行业动态 更新时间:2024-10-24 10:17:44
本文介绍了如何在固定位置将子窗体固定在父窗体中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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.

更多推荐

如何在固定位置将子窗体固定在父窗体中?

本文发布于:2023-11-26 08:11:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   位置   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!