提高控件速度框(C++-CLI WinForms)
我用c++做了一个控件,允许用户在一个不规则的盒子里选择一个位置,位置不同,有的被挡住,有的被填充,具有这样的特点:
可以在多行中创建多列(不是相同,因此可以第一行有 3 列,第二行有 1,第三行有 5)
每个位置有不同的状态:阻塞、填充、空、选定(因此可以同时具有其中一些状态:阻塞和空、阻塞和填充、空) p
- < >用户可以选择一个或多个位置
每个填充或空的位置都有工具提示文本和不同的背景图像。
用于添加/删除行/列的上下文菜单。
行和列标题,数字/字母数字,升序/降序。
该控件的结构是Container->(nRows x RowClass)和RowClass->(nCols x ColumnClass)。每列都包含一个 TableLayoutPanel,因此我可以模拟卡住和凸起的效果。
查看网络上的不同主题,我发现了一些想法和我对速度所做的改进基本上是使用 SendMessage 进行 SuspendDrawing (在绘制它们之前创建所有行和列并调整它们的大小),双缓冲每个控件并添加 BeginEdit/ EndEdit 方法到容器,该方法在创建行和列时 SuspendDrawing 并阻止行和列调整大小(每个 RowClass 都相同)。
对于相对较小的盒子,它的工作效果还不错,比如 20 行 x 20 列,但是当它有 40 行 x 30 列(1.200 TableLayoutPanel)时,即使在快速计算机中,它也会变得非常慢。
我还尝试为每个 RowClass 使用一个 TableLayoutPanel (具有所需的列数),但问题是如何绘制边框以便分别选择每一列、每个单元格的工具提示和背景图像。
那么,问题是:我可以尝试哪些改进吗?
我一直认为像《魔兽争霸》或类似的策略游戏在屏幕上具有良好的速度,具有数千个图形和计算,但我不认为一个专业的程序员,所以我不知道这可能是什么技术,以及它是否是正确的方法。
也许它可能是像带有一行图像的图像,或者不同于一类类的类的东西,但我不知道......
可能这是一个设计问题,所以,任何关于如何使用这些规范创建快速控件的想法都会很棒。
无论如何,感谢您阅读我的问题,任何评论都将受到欢迎! 米格尔
I've made a control in c++ to allow the user to select a position in an irregular box with different positions, some of them blocked, some of them filled, with this characteristics:
Can create multiple columns in multiple rows (not the same, so it can have the first row with 3 columns, the second with 1 and the third with 5)
Different states each position: blocked, filled, empty, selected (so it can have some of them at the same time: blocked & empty, blocked & filled, empty & selected)
The user can select one or multiple position
It has tooltip texts and different background images for each filled or empty position.
Contextual menu to add/delete rows/columns.
Row and Column headers, numeric/alphanumeric, ascending/descending.
The structure of the control is Container->(nRows x RowClass) and RowClass->(nCols x ColumnClass). Each column contains a TableLayoutPanel so I can simulate the stuck and raised effects.
Loocking different topics on the web, I found some ideas and the improvements I've done for the speed are basically SuspendDrawing with SendMessage (to create and resize all the rows and columns before painting them), double buffering each control and adding a BeginEdit/EndEdit method to the Container that SuspendDrawing and blocks row and column resizing while creating rows and columns (and the same for each RowClass).
It works not so bad with relative small boxes, lets say 20 rows x 20 columns, but when it has 40 rows x 30 columns (1.200 TableLayoutPanel's) it is going really slow even in a fast computer.
I also tried with one TableLayoutPanel (with the required number of columns) per RowClass, but the problem is how to draw borders in order to select each column separatedly, tooltips and background image for each cell.
So, the question: is there any improvements I can try?
I've been thinking that strategy games like warcraft or similar they have good speed on screen with thousands of graphics and calculations, but I'm not a professional programmer so I don't know wich could be the technology and if it is the right way..
Maybe it could be something like an image with a row of images, or something different than a class of classes of classes, but I have no idea...
Probably it is a design problem so, any idea on how would you create a fast control with those specifications will be great.
Thanks anyway for reading my question, any comments will be wellcome!
Miguel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对此没有明确的解决方案,您将不得不放弃 TLP。控件是一个非常太昂贵的对象,任何拥有超过一百个控件的窗体都会陷入困境。
首先看一下支持网格显示的内置控件类型。 ListView with View = Details 对于不可编辑的网格,DataGridView 对于可编辑的网格。如果这不符合您的要求,那么您就必须自己制作。您需要实现的关键事项是用于绘制控件视觉外观的 OnPaint() 方法以及用于执行命中测试和实现行为的 OnMouseDown 或 OnClick。
There is no clean fix for this, you will have to give up on TLP. A control is a much too expensive object, any form that has more than a hundred of them is going to suck mud.
First look at the built-in control types that support a grid-like display. ListView with View = Details for non-editable grids, DataGridView for editable ones. If that doesn't fit your bill then you'll have to make your own. Key things you'll need to implement is the OnPaint() method to draw the visual appearance of the control and OnMouseDown or OnClick to do hit-testing and implement behavior.
视频游戏至少在 GPU 上卸载图形表示(GPU 就是为此目的而构建的)。我不认为盒子的表示是瓶颈,而是到达那里的计算/步骤。
要么发布你的代码/代码片段,要么解释你对算法的使用,因为当输入增加时,糟糕的算法会让你的程序变得非常慢——看看计算复杂性,这是算法课程提出的东西。
http://en.wikipedia.org/wiki/Computational_complexity_theory
Videogames offload the graphical representations atleast on the GPU (which are built for just that purpose). I do not think the representation of the boxes is the bottleneck, rather the calculations/steps to get there.
Either post your code / a snippet of your code or explain your use of algorithms, because a bad algorithm will make your program very slow when input increases -- have a look on Computational Complexity, something brought up by algorithm courses.
http://en.wikipedia.org/wiki/Computational_complexity_theory
这是代码的一部分(整个代码真的很大),其中完成了一些计算..
In ControlClass::
in FilaClass:
in ColumnaClass:
我认为这些是计算的大部分内容..
有点未注释,并且是西班牙语,但任何帮助都会非常有用!
无论如何,谢谢!
Here is a part of the code (the whole code is really huge) where some calculations are done..
In ControlClass::
in FilaClass:
in ColumnaClass:
I think those are most part of the calculations..
A little bit uncommented, and in spanish, but any help will be really useful!
Thanks anyway!