C#:如何让用户控件正确地自动调整大小

C#: How to get a user control to properly auto size itself(C#:如何让用户控件正确地自动调整大小)
本文介绍了C#:如何让用户控件正确地自动调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UserControl,它由一个 Label(顶部)、一个 FlowLayoutPanel(填充、TopDown 流和不换行)和一个面板(底部).用户控件根据获取的内容列表创建许多控件,并将它们添加到 FlowLayoutPanel.

I have a UserControl which consists of a Label (Top), a FlowLayoutPanel (Fill, TopDown flow and no wrap) and a Panel (Bottom). The user control creates a number of controls, based on a list of stuff it gets, and adds them to the FlowLayoutPanel.

我怎样才能让这个 UserControl 正确调整自身大小,使 FlowLayoutPanel 没有任何滚动条?我尝试在 FlowLayoutPanelUserControl 本身上使用 AutoSizeAutoSizeMode 的各种组合,但我可以似乎没有让它工作.要么我最终得到的东西根本不会自行调整大小,要么它没有变得足够大,要么它被压扁到几乎没有.

How can I get this UserControl to properly resize itself so that the FlowLayoutPanel does not have any scroll bars? I have tried to use various combinations of AutoSize and AutoSizeMode on the FlowLayoutPanel and the UserControl itself, but I can't seem to get it working. Either I end up with something that doesn't resize itself at all, or it doesn't become big enough or it is squished down to almost nothing.

推荐答案

感谢所有建议.这次的解决方案似乎将 FlowLayoutPanel UserControlAutoSize 设置为 true代码> 本身.

Thanks for all the suggestions. The solution this time seemed to set AutoSize to true for both the FlowLayoutPanel and the UserControl itself.

现在,如何获取将包含此 UserControl 以及其他一些控件的表单,目前我还不太清楚,但我想应该是一个单独的问题...

Now, how to get the form which will contain this UserControl as well as some other controls, that I can't quite figure out at the moment, but I guess that should be a separate question...

这篇关于C#:如何让用户控件正确地自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)