13

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?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Roddy
  • 66,617
  • 42
  • 165
  • 277
  • 1
    The *state* one doesn't seem to be very much offered. (1) - It is not documented. (2) - The only code which includes/excludes it (`SetDesignVisible` of 'TControl' and 'TWinControl') is documented as *"is used internally by Delphi during form design"*. (3) - Not used by the VCL, the only code that ever calls `SetDesignVisible` is in 'ribbons'. I'd try to use the 'control style'. – Sertac Akyuz Nov 19 '13 at 19:53
  • @Sertac `SetDesignVisible` is the property setter and is indeed the only routine setting the flag, but I think you're drawing the wrong conclusion from it: it's more important where and whether the flag is being consulted instead of being set. – NGLN Nov 20 '13 at 06:00
  • @NGLN - You're wrong, `SetDesignVisible` is not a property setter. Additionally, I'm saying it's not used by VCL, where the flag is being tested has no importance unless it's set by some code. – Sertac Akyuz Nov 20 '13 at 07:36
  • @Sertac Ok, it's not a property setter... ;-) But I mean to say that although the VCL doesn't set the flag, component builders might do. It's about the framework that provides instead of the framework that uses. I don't think there is much setting of the `csNoDesignVisible` flag in the VCL either. – NGLN Nov 20 '13 at 09:40
  • 1
    `csNoDesignVisible` is used in a few places, PopupDataList, ActionClientItem, ActionPopupMenu, TabSheet, notebook Page and again in ribbon are the ones I can find. Of course developers may use `csDesignerHide`, I didn't conclude/say otherwise (just suggested against it). But IMO, either it should be evident what it does, or it should be documented to be able to use it. It's only after your answer I have some slight idea to its purpose. :) – Sertac Akyuz Nov 20 '13 at 10:05

1 Answers1

12

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:

enter image description here

  1. All with default settings
  2. StateControl1.DesignerHide = True
  3. StyleControl1.NoDesignVisible = True and StyleControl1.Visible = False
Community
  • 1
  • 1
NGLN
  • 43,011
  • 8
  • 105
  • 200
  • Thanks! *TControlStyle.csNoDesignVisible works only in conjuction with the Visible property* Ah - the screenshot explains it best! – Roddy Nov 20 '13 at 09:34