TControlState.csDesignerHide vs. TControlStyle.csNoDesignVisible

旧巷老猫 提交于 2019-12-04 19:13:49

问题


The VCL seems to offer two mechanisms for hiding controls from form designers : TControlState.csDesignerHide and TControlStyle.csNoDesignVisible.

What's the difference between them as far as the IDE is concerned? Which should you use when?


回答1:


Summary

Use TControlState.csDesignerHide to prevent the control from drawing.

Use TControlStyle.csNoDesignVisible to mimic runtime behaviour of the Visible property.

Elaboration

Nice question! There simply must be a difference between them, so I did a little investigation.

Searching for usage in the Controls unit, we find that:

  • TControlState.csDesignerHide is used in: TControl.InvalidateControl, TWinControl.UpdateShowing, TWinControl.PaintHandler, TWinControl.PaintControls,
  • in addition to those methods, TControlStyle.csNoDesignVisible is also used in: TControl.Show, TControl.Repaint, TControl.CMVisibleChanged, TWinControl.AlignControls, TWinControl.ControlAtPos, TWinControl.CMVisibleChanged, TWinControl.GetControlExtents, TWinControl.CalcConstraints, TWinControl.CanAutoSize.

Thus TControlState.csDesignerHide is only used in painting operations whereas TControlStyle.csNoDesignVisible is also used in position and alignment operation.

In other words, use:

  • TControlState.csDesignerHide if you only want control over visibility,
  • TControlStyle.csNoDesignVisible if you also want control over presence.

Furthermore, TControlStyle.csNoDesignVisible works only in conjuction with the Visible property. It has no effect when Visible is set True. (Normally, the Visible property only affects runtime behaviour).

To illustrate the difference, hereby three screen shots of a form designer. On the form are placed from left to right: a "TStyleControl" with a property controlling TControlStyle.csNoDesignVisible, a Panel, a "TStateControl" with a property controlling TControlState.csDesignerHide and another Panel, all with the Align property set to alLeft:

  1. All with default settings
  2. StateControl1.DesignerHide = True
  3. StyleControl1.NoDesignVisible = True and StyleControl1.Visible = False


来源:https://stackoverflow.com/questions/20068623/tcontrolstate-csdesignerhide-vs-tcontrolstyle-csnodesignvisible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!