如何在 Winforms 中创建可折叠面板作为自定义控件?
我能想到的最接近的是 GroupBox 控件,它在顶部有一个自定义绘图来标识面板。
可行吗?我已经完成了独立的自定义控件,如按钮、滑块、颜色选择器,但不完全确定这种绘图是否可以在 GroupBox 上完成?
我需要 GroupBox 或 TabPanel 的分组。
网上有我可以使用的替代方案吗?
在开始做之前先探索一下替代方案。
The closest I can think of using is the GroupBox control which has a custom drawing at the top identifying the panel.
Is it doable? I have done independent custom controls like buttons, sliders, color pickers, but not totally sure if this sort of drawing can be done on a GroupBox?
I would need the grouping of a GroupBox or a TabPanel.
Are there any alternatives on the net that I can use?
Just exploring the alternatives before I start doing it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们使用的技术是创建多个停靠在框架顶部的面板并将其高度设置为零。然后,当我们想要显示面板时,我们正确设置其高度。 Winforms 自动重排其他面板以适应新面板。
您还可以创建一个循环计时器,每隔几百毫秒触发一次,将面板的高度增加几个像素,直到达到完整尺寸。这会创建一个面板展开到位的漂亮动画。
A technique we used was to create multiple panels docked to the top of a frame and set their height to zero. Then when we wanted to display a panel we set its height correctly. Winforms automatically reflows other panels to accommodate the new one.
You can also create a recurring timer to trigger every few hundred milliseconds that increases the panel's height by a few pixels until it reaches full size. This creates a nice animation of the panel expanding into place.
看看其他人是如何做到这一点的。代码项目有很多。尝试在那里搜索。
我不久前使用过这个,并且很喜欢它:
Windows XP 风格的可折叠面板栏
See how others have done this. Code Project's got a bunch. Try searching there.
I used this one a while ago and liked it:
Windows XP style Collapsible Panel Bar
为什么不直接创建一个复合控件呢?效果是.. 2 个面板或一个标签和一个面板或任何适合您需要的东西。绘制它不会那么困难,但对于您想要的功能来说似乎过于复杂。我完全没有抓住重点吗?
Why not just create a composite control? Something to the effect of.. 2 panels or a label and a panel or whatever suits your needs. Drawing it wouldn't be all that difficult but seems overly complicated for your desired functionality. Am I completely missing the mark?