具有大量控件的C#/ .net表单的性能

时间:2021-12-07 00:02:17

Does the number of controls on a form affect its performance? What if the controls are marked invisible? What if the several controls are visible, but entirely covered by only a few controls (like a panel containing a couple of controls)?

表单上的控件数量是否会影响其性能?如果控件被标记为不可见怎么办?如果几个控件可见,但只有少数几个控件(如包含几个控件的面​​板)完全覆盖怎么办?

I'm asking this from a perspective of applications like 3d modeling packages, video editing software, etc. They've got hidden panels, tabs, rollouts, animated drawers and what not.

我从3D建模软件包,视频编辑软件等应用程序的角度问这个问题。他们有隐藏的面板,标签,卷展栏,动画抽屉等等。

Has anyone done any such performance tests? Is considering this worthwhile?

有人做过任何这样的性能测试吗?正在考虑这个值得吗?

2 个解决方案

#1


2  

Without doing any performance test it's easy to say that too many controls has performance issue,

没有进行任何性能测试,很容易说太多控件存在性能问题,

  • The memory usage increased (UI objects are very huge).
  • 内存使用量增加(UI对象非常庞大)。
  • OnPaint and other message base methods will be called (for control or for parent in inheritance hierarchy)
  • 将调用OnPaint和其他消息库方法(用于控制或继承层次结构中的父级)

#2


3  

Yes. Outside of the drawing, each control uses it's own window handle just by initializing it. So even invisible or hidden, it will affect performance.

是。在绘图之外,每个控件只是通过初始化它来使用它自己的窗口句柄。所以即使看不见或隐藏,也会影响性能。

The type of control makes a difference too. 3rd party or custom controls will sometimes be composed of multiple controls, each having it's own handle.

控制的类型也有所不同。第三方或自定义控件有时会由多个控件组成,每个控件都有自己的句柄。

Usually the up front consideration for the amount of controls is done in the usability context and that generally should help avoid performance issues.

通常,控制量的前期考虑是在可用性上下文中完成的,通常应该有助于避免性能问题。

#1


2  

Without doing any performance test it's easy to say that too many controls has performance issue,

没有进行任何性能测试,很容易说太多控件存在性能问题,

  • The memory usage increased (UI objects are very huge).
  • 内存使用量增加(UI对象非常庞大)。
  • OnPaint and other message base methods will be called (for control or for parent in inheritance hierarchy)
  • 将调用OnPaint和其他消息库方法(用于控制或继承层次结构中的父级)

#2


3  

Yes. Outside of the drawing, each control uses it's own window handle just by initializing it. So even invisible or hidden, it will affect performance.

是。在绘图之外,每个控件只是通过初始化它来使用它自己的窗口句柄。所以即使看不见或隐藏,也会影响性能。

The type of control makes a difference too. 3rd party or custom controls will sometimes be composed of multiple controls, each having it's own handle.

控制的类型也有所不同。第三方或自定义控件有时会由多个控件组成,每个控件都有自己的句柄。

Usually the up front consideration for the amount of controls is done in the usability context and that generally should help avoid performance issues.

通常,控制量的前期考虑是在可用性上下文中完成的,通常应该有助于避免性能问题。