C#: How to get a user control to properly auto size itself(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 没有任何滚动条?我尝试在 FlowLayoutPanel 和 UserControl 本身上使用 AutoSize 和 AutoSizeMode 的各种组合,但我可以似乎没有让它工作.要么我最终得到的东西根本不会自行调整大小,要么它没有变得足够大,要么它被压扁到几乎没有.
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 和 UserControl的 AutoSize 设置为 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#:如何让用户控件正确地自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C#:如何让用户控件正确地自动调整大小
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
