使用Dock.Fill的UserControl问题

编程入门 行业动态 更新时间:2024-10-10 01:20:01
本文介绍了使用Dock.Fill的UserControl问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我在尝试填充UserControl 时遇到问题 在面板内. 我创建了一些UserControl.我的问题是,在尝试将它们填充到面板中时,有些正在按预期调整大小,而有些则没有反应,并保持相同的大小. ??? 另一件事-正常反应的控件是PictrueBox类型. 其他的是包含许多控件的Panel. thx!

hi all, i''ve encountered a problem while trying to fill a UserControl inside a panel. i''ve created some UserControl''s. my problem is that while trying to fill them in a panel, some are resizing as expected and some don''t react and remain at the same size. ??? another thing - the controls whom react normally are PictrueBox type. the other ones are Panels containing many controls. thx!

推荐答案

这是一个旧帖子,但无论如何,我也遇到过类似的问题. 我的一组控件未正确对接(已正确放置,但是一旦我调整窗体的大小就保持相同大小(我在运行时添加了控件).因此,我实际上不得不编写一些方法来编写代码调整整个控件层次结构的大小. Hi, It''s an old post but anyway, I have experienced similar problems. A set of my controls was not docking properly ( it was placed properly , but once I resized the form the controls stayed of the same size ( I was adding the controls at runtime). So , I actualy hadd to code a couple of methods to resize the whole control hierarchy. private static void ResizeChildsInt(Control c,bool recursive) { Rectangle r = c.DisplayRectangle; foreach (Control item in c.Controls) { if (item.Dock == DockStyle.Top) { item.Top = r.Top; item.Left = r.Left; item.Width = r.Width; if (item.Height > r.Height) { item.Height = r.Height; } r = new Rectangle(r.X, r.Y + item.Height, r.Width, r.Height - item.Height); } else if (item.Dock == DockStyle.Bottom) { int bottom = r.Bottom - item.Height; if (item.Height > r.Height) { item.Height = r.Height; } item.Top = item.Height - r.Bottom; item.Left = r.Left; item.Width = r.Width; r = new Rectangle(r.X, r.Y, r.Width, r.Height - item.Height); } else if (item.Dock == DockStyle.Left) { int width = item.Width; if (width > r.Width) { width = r.Width; } item.Top = r.Top; item.Left = r.Left; item.Height = r.Height; item.Width = width; r = new Rectangle(r.X + item.Width, r.Y, r.Width - item.Width, r.Height); } else if (item.Dock == DockStyle.Right) { int width = item.Width; if (width > r.Width) { width = r.Width; } item.Top = r.Top; item.Left = r.Right - item.Width; item.Height = r.Height; item.Width = width; r = new Rectangle(r.X, r.Y, r.Width - item.Width, r.Height); } } //Fill foreach (Control item in c.Controls) { if (item.Dock == DockStyle.Fill) { item.Top = r.Top; item.Left = r.Left; item.Width = r.Width; item.Height = r.Height; } } //Recursive if (recursive) { foreach (Control item in c.Controls) { if (item is UserControl == false) { ResizeChildsInt(item, recursive); } } } } public static void ResizeChilds(Control c) { c.SuspendLayout(); ResizeChildsInt(c, true); c.ResumeLayout(); }

每次调整控件大小时,只需调用静态方法ResizeChilds.

Just call the static method ResizeChilds each time the control is resized.

您设置了这些面板停靠时要做什么?我建议他们按照他们的指示去做. What have you set those panels to do when they are docked ? I''d suggest they are doing what they are told.

更多推荐

使用Dock.Fill的UserControl问题

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

发布评论

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

>www.elefans.com

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