TabPage.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jackson Harper ([email protected])
  24. using System;
  25. using System.Drawing;
  26. namespace System.Windows.Forms {
  27. public class TabPage : Panel {
  28. private int image_index = -1;
  29. private string tooltip_text = String.Empty;
  30. public TabPage ()
  31. {
  32. }
  33. public TabPage (string text) : base ()
  34. {
  35. Text = text;
  36. }
  37. public override AnchorStyles Anchor {
  38. get { return base.Anchor; }
  39. set { base.Anchor = value; }
  40. }
  41. public override DockStyle Dock {
  42. get { return base.Dock; }
  43. set { base.Dock = value; }
  44. }
  45. public new bool Enabled {
  46. get { return base.Enabled; }
  47. set { base.Enabled = value; }
  48. }
  49. public int ImageIndex {
  50. get { return image_index; }
  51. set {
  52. if (image_index == value)
  53. return;
  54. image_index = value;
  55. UpdateOwner ();
  56. }
  57. }
  58. public new int TabIndex {
  59. get { return base.TabIndex; }
  60. set { base.TabIndex = value; }
  61. }
  62. public new bool TabStop {
  63. get { return base.TabStop; }
  64. set { base.TabStop = value; }
  65. }
  66. public override string Text {
  67. get { return base.Text; }
  68. set {
  69. if (value == Text)
  70. return;
  71. base.Text = value;
  72. UpdateOwner ();
  73. }
  74. }
  75. public string ToolTipText {
  76. get { return tooltip_text; }
  77. set {
  78. if (value == null)
  79. value = String.Empty;
  80. tooltip_text = value;
  81. }
  82. }
  83. public new bool Visible {
  84. get { return base.Visible; }
  85. set { base.Visible = value; }
  86. }
  87. public new event EventHandler DockChanged {
  88. add { base.DockChanged += value; }
  89. remove { base.DockChanged -= value; }
  90. }
  91. public new event EventHandler EnabledChanged {
  92. add { base.EnabledChanged += value; }
  93. remove { base.EnabledChanged -= value; }
  94. }
  95. public new event EventHandler TabIndexChanged {
  96. add { base.TabIndexChanged += value; }
  97. remove { base.TabIndexChanged -= value; }
  98. }
  99. public new event EventHandler TabStopChanged {
  100. add { base.TabStopChanged += value; }
  101. remove { base.TabStopChanged -= value; }
  102. }
  103. public new event EventHandler VisibleChanged {
  104. add { base.VisibleChanged += value; }
  105. remove { base.VisibleChanged -= value; }
  106. }
  107. public static TabPage GetTabPageOfComponent (object comp)
  108. {
  109. Control control = comp as Control;
  110. if (control == null)
  111. return null;
  112. control = control.Parent;
  113. while (control != null) {
  114. if (control is TabPage)
  115. break;
  116. control = control.Parent;
  117. }
  118. return control as TabPage;
  119. }
  120. public override string ToString ()
  121. {
  122. return "TabPage: {" + Text + "}";
  123. }
  124. private void UpdateOwner ()
  125. {
  126. if (Owner != null) {
  127. // Will do some loving to the owner here
  128. }
  129. }
  130. private TabControl Owner {
  131. get { return base.Parent as TabControl; }
  132. }
  133. protected override ControlCollection CreateControlsInstance ()
  134. {
  135. return new TabPageControlCollection (this);
  136. }
  137. protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
  138. {
  139. if (Owner == null) {
  140. Rectangle display = Owner.DisplayRectangle;
  141. base.SetBoundsCore (Owner.DisplayRectangle.X, Owner.DisplayRectangle.Y,
  142. Owner.DisplayRectangle.Width, Owner.DisplayRectangle.Height,
  143. BoundsSpecified.All);
  144. } else {
  145. base.SetBoundsCore(x, y, width, height, specified);
  146. }
  147. }
  148. public class TabPageControlCollection : ControlCollection {
  149. private TabPage owner;
  150. public TabPageControlCollection (TabPage owner) : base (owner)
  151. {
  152. this.owner = owner;
  153. }
  154. public void Add (Control value)
  155. {
  156. base.Add (value);
  157. }
  158. }
  159. }
  160. }