简体   繁体   English

如何在Winforms C#中创建控件的叠加部分?

[英]How to create an overlay part of control in Winforms C#?

I need to create a custom control that has an expandable part as a panel and a textbox part. 我需要创建一个自定义控件,该控件具有一个可扩展部分作为面板和一个文本框部分。 The expandable part is a panel, that will either be visible or invisible. 可扩展部分是一个面板,它将是可见的或不可见的。 But when the panel is visible/expanded directly under the textbox, I do not want the adjacent controls to shift down below the panel, but the panel should just overlay the controls that are there just under the custom control. 但是,当该面板在文本框正下方可见/扩展时,我不希望相邻的控件向下移动到该面板下方,但是该面板应仅覆盖自定义控件下方的控件。 How would I implement this in Winforms C# project? 我将如何在Winforms C#项目中实现这一点? I am open to using user control for this scenario. 我愿意在这种情况下使用用户控件。

Thanks Sunil 谢谢苏尼尔

I think your implementation of expanding and collapsing is not the best, because you are just overlaying the controls instead of hiding them. 我认为扩展和折叠的实现不是最好的,因为您只是覆盖控件而不是隐藏它们。 One of the disadvantages is that the overlaid controls might by focussed by pressing tab and they might have a value which I think it is out of target. 缺点之一是,重叠的控件可能会通过按Tab键聚焦,并且它们可能具有我认为超出目标的值。

I would suggest another implementation by creating two panels (one for the header and another one for the content) and when the collapse button is pressed then the content's panel will be hidden by sitting its Visible property to false and its Hight to 0 . 我建议通过创建两个面板(一个用于标题,另一个用于内容)来建议另一种实现方式,当按下折叠按钮时,通过将其Visible属性设置为false并将其Hight0可以隐藏内容的面板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM