C#的WinForms:有效地显示许多控件 [英] C# Winforms: Efficiently Displaying Many Controls
问题描述
我建立了包括15×15 = 225按键,并且需要是可调整大小的控制。因为它是一个网格,锚定和对接将无法工作。我都试过的TableLayoutPanel以及处理resize事件手动放置和尺寸控制。在这两种情况下,调整大小是不可接受的缓慢。暂停/中时,我手动操作的布局不利于调整大小功能恢复布局。
I'm building a control that comprises 15x15 = 225 buttons, and needs to be resizable. Because it's a grid, anchoring and docking won't work. I've tried both TableLayoutPanel as well as handling the resize event to manually place and size controls. In both cases, resizing is unacceptably slow. Suspend/Resume Layout in the resize function when I'm manually handling the layout doesn't help.
有什么根本的是我可以改变,以加快速度,或者这仅仅是一个本地控制的限制吗?我明白我可以从头开始构建一个自定义的控制,处理的点击和画自己 - 尽管我宁愿坚持如果可能,本地控件
Is there something fundamental that I can change to speed things up, or is this just a limitation of the native controls? I understand I can build a custom control from scratch, handling the clicks and painting myself -- though I'd prefer to stick with the native controls if possible.
修改
我知道这是一个很多按钮。我的问题是一个技术性的;而不是一个关于UI设计。
I know it's a lot of buttons. My question is a technical one; not one about UI design.
推荐答案
的WinForms不处理的同时不幸这显示许多控件。
WinForms doesn't handle displaying this many controls at the same time unfortunately.
如果我是你情我愿首先考虑,如果我能在几页分割的形式。在许多情况下,这将是比较容易理解的用户也是如此。
If I were in your situation I would first consider if I could split up the form in several pages. In many cases that would be easier to understand for the user as well.
不过你的情况似乎并不成为一个选项。你在做类似扫雷的游戏风格?有你有按钮,都是可点击的网格。在这种情况下,我建议你去一个自定义的所有者绘制控件,您巩固一个控制所有的按钮。不要构建包含225按钮的复合控件 - 这将于事无补: - )
But in your case that doesn't seem to be an option. Are you making something like a minesweeper style game? There you have a grid of buttons that all are clickable. In such a situation I would suggest you go for a custom owner drawn control where you consolidate all the buttons in one control. Don't build a composite control that contains 225 buttons - that won't help at all :-)
一个最后的选择可能是切换到WPF。 WPF使用硬件加速渲染,因此可能会更快,但有这么多的控制甚至没有可能的帮助。
A final option could be to switch to WPF. WPF uses hardware accelerated rendering so it may be faster, but with so many controls not even that may help.
这篇关于C#的WinForms:有效地显示许多控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!