ParentControl.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.ComponentModel;
  2. namespace FastReport.Dialog
  3. {
  4. /// <summary>
  5. /// Base class for controls that may contain child controls.
  6. /// </summary>
  7. public partial class ParentControl : DialogControl, IParent
  8. {
  9. #region Fields
  10. private DialogComponentCollection controls;
  11. #endregion
  12. #region Properties
  13. /// <summary>
  14. /// Gets the collection of child controls.
  15. /// </summary>
  16. [Browsable(false)]
  17. public DialogComponentCollection Controls
  18. {
  19. get { return controls; }
  20. }
  21. #endregion
  22. #region IParent
  23. /// <inheritdoc/>
  24. public virtual void GetChildObjects(ObjectCollection list)
  25. {
  26. foreach (DialogComponentBase c in controls)
  27. {
  28. list.Add(c);
  29. }
  30. }
  31. /// <inheritdoc/>
  32. public virtual bool CanContain(Base child)
  33. {
  34. return (child is DialogComponentBase);
  35. }
  36. /// <inheritdoc/>
  37. public virtual void AddChild(Base child)
  38. {
  39. if (child is DialogComponentBase)
  40. controls.Add(child as DialogComponentBase);
  41. }
  42. /// <inheritdoc/>
  43. public virtual void RemoveChild(Base child)
  44. {
  45. if (child is DialogComponentBase)
  46. controls.Remove(child as DialogComponentBase);
  47. }
  48. /// <inheritdoc/>
  49. public virtual int GetChildOrder(Base child)
  50. {
  51. return controls.IndexOf(child as DialogComponentBase);
  52. }
  53. /// <inheritdoc/>
  54. public virtual void SetChildOrder(Base child, int order)
  55. {
  56. int oldOrder = child.ZOrder;
  57. if (oldOrder != -1 && order != -1 && oldOrder != order)
  58. {
  59. if (order > controls.Count)
  60. order = controls.Count;
  61. if (oldOrder <= order)
  62. order--;
  63. controls.Remove(child as DialogComponentBase);
  64. controls.Insert(order, child as DialogComponentBase);
  65. }
  66. }
  67. /// <inheritdoc/>
  68. public virtual void UpdateLayout(float dx, float dy)
  69. {
  70. // do nothing
  71. }
  72. #endregion
  73. /// <summary>
  74. /// Initializes a new instance of the <b>ParentControl</b> class with default settings.
  75. /// </summary>
  76. public ParentControl()
  77. {
  78. controls = new DialogComponentCollection(this);
  79. }
  80. }
  81. }