如何使WinForms中的控件遵循父控件的对齐? [英] How to make controls in WinForms to follow the alignment of Parent Controls?

查看:94
本文介绍了如何使WinForms中的控件遵循父控件的对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Every One



我对这个C#和WinForms非常陌生。最近我用C#编写了一个WinForms应用程序。我在一个窗口中有一个组合框。当我尝试最大化/调整窗口大小时。它缺少其父容器的对齐方式,即Window。无论我知道什么控件来解决这个问题,我都尝试了Anchoring等。所以,请让我知道是否有任何直接的方法或任何其他方法来解决这个问题。



在此先感谢



Sri

解决方案

最好的方法是将属性组合在一起 System.Windows.Forms.Controls.Dock System.Windows.Forms.Controls.Padding 。在某些情况下, Anchor 也很有用,但要小心使用它,因为它往往会导致更多的闪烁(本质上,主要原因是它包含一些本机Windows控件)表单控件类非常陈旧;它们是在计算机性能不足以允许有效防止闪烁的情况下创建的。



基本上,所有设计都基于许多面板以所需方式嵌套,其他控件停靠在这种面板树的树叶中,不使用 System.Windows.Forms.DockStyle.None



在我过去的回答中,我提供了一个基本的代码示例来说明这个想法:如何停靠按钮,以便它可以用表格调整 [ ^ ]。



另请参阅:

Zom Out在屏幕分辨率改变时出现故障 [ ^ ],

GUI外观 - C#.Net [ ^ ]。



-SA

Hello Every One

I am very much new to this C# and WinForms. Recently I was programming a WinForms application using C#. I Have a group box in a Window. The when I try to Maximize/ Resize the window. It is missing the alignment of its parent container which is the Window. I tried Anchoring etc., whatever the controls I know to solve this issue. So please let me know whether there is any direct approach or any other approach to solve this problem.

Thanks in Advance

Sri

解决方案

The best approach to this is the combination of the properties System.Windows.Forms.Controls.Dock and System.Windows.Forms.Controls.Padding. In certain cases, Anchor is also helpful, but use it with care, as it tends to cause more flicker (essentially, main reason for it is that some native Windows controls wrapped as Forms control classes are very old; they were created when computer performance was no good enough to allow for effective measures against flicker).

Basically, all the design is based on many panels nested in required way, with other controls docked in leaves of such panel tree, without the use of System.Windows.Forms.DockStyle.None.

In my past answer, I provided a rudimentary code sample to illustrate the idea: how to dock button so that it can adjust with the form[^].

Please see also:
Zom Out malfunctions when Screen resolution changes[^],
GUI Apperance - C#.Net[^].

—SA


这篇关于如何使WinForms中的控件遵循父控件的对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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