TabPage.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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-2005 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jackson Harper ([email protected])
  24. using System;
  25. using System.ComponentModel;
  26. using System.ComponentModel.Design;
  27. using System.Drawing;
  28. namespace System.Windows.Forms {
  29. [DefaultEvent("Click")]
  30. [DesignTimeVisible(false)]
  31. [DefaultProperty("Text")]
  32. [Designer("System.Windows.Forms.Design.TabPageDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  33. [ToolboxItem(false)]
  34. public class TabPage : Panel {
  35. #region Fields
  36. private int image_index = -1;
  37. private string tooltip_text = String.Empty;
  38. private Rectangle tab_bounds;
  39. private int row;
  40. private bool use_visual_style_back_color;
  41. #endregion // Fields
  42. #region Public Constructors
  43. public TabPage ()
  44. {
  45. Visible = true;
  46. SetStyle (ControlStyles.CacheText, true);
  47. }
  48. public TabPage (string text) : base ()
  49. {
  50. base.Text = text;
  51. }
  52. #endregion // Public Constructors
  53. #region .NET 2.0 Public Instance Properties
  54. #if NET_2_0
  55. public bool UseVisualStyleBackColor {
  56. get { return use_visual_style_back_color; }
  57. set { use_visual_style_back_color = value; }
  58. }
  59. public override Color BackColor {
  60. get { return base.BackColor; }
  61. set { use_visual_style_back_color = false; base.BackColor = value; }
  62. }
  63. #endif
  64. #endregion
  65. #region Public Instance Properties
  66. [Browsable(false)]
  67. [EditorBrowsable(EditorBrowsableState.Never)]
  68. public override AnchorStyles Anchor {
  69. get { return base.Anchor; }
  70. set { base.Anchor = value; }
  71. }
  72. [Browsable(false)]
  73. [EditorBrowsable(EditorBrowsableState.Never)]
  74. public override DockStyle Dock {
  75. get { return base.Dock; }
  76. set { base.Dock = value; }
  77. }
  78. [Browsable(false)]
  79. [EditorBrowsable(EditorBrowsableState.Never)]
  80. public new bool Enabled {
  81. get { return base.Enabled; }
  82. set { base.Enabled = value; }
  83. }
  84. [DefaultValue(-1)]
  85. [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
  86. [Localizable(true)]
  87. [TypeConverter(typeof(ImageIndexConverter))]
  88. public int ImageIndex {
  89. get { return image_index; }
  90. set {
  91. if (image_index == value)
  92. return;
  93. image_index = value;
  94. UpdateOwner ();
  95. }
  96. }
  97. [Browsable(false)]
  98. [EditorBrowsable(EditorBrowsableState.Never)]
  99. public new int TabIndex {
  100. get { return base.TabIndex; }
  101. set { base.TabIndex = value; }
  102. }
  103. [Browsable(false)]
  104. [EditorBrowsable(EditorBrowsableState.Never)]
  105. public new bool TabStop {
  106. get { return base.TabStop; }
  107. set { base.TabStop = value; }
  108. }
  109. [Browsable(true)]
  110. [Localizable(true)]
  111. public override string Text {
  112. get { return base.Text; }
  113. set {
  114. if (value == base.Text)
  115. return;
  116. base.Text = value;
  117. UpdateOwner ();
  118. }
  119. }
  120. [Localizable(true)]
  121. [DefaultValue("")]
  122. public string ToolTipText {
  123. get { return tooltip_text; }
  124. set {
  125. if (value == null)
  126. value = String.Empty;
  127. tooltip_text = value;
  128. }
  129. }
  130. [Browsable(false)]
  131. [EditorBrowsable(EditorBrowsableState.Never)]
  132. public new bool Visible {
  133. get { return base.Visible; }
  134. set { /* according to MS docs we can ignore this */ }
  135. }
  136. #endregion // Public Instance Properties
  137. #region Public Static Methods
  138. public static TabPage GetTabPageOfComponent (object comp)
  139. {
  140. Control control = comp as Control;
  141. if (control == null)
  142. return null;
  143. control = control.Parent;
  144. while (control != null) {
  145. if (control is TabPage)
  146. break;
  147. control = control.Parent;
  148. }
  149. return control as TabPage;
  150. }
  151. #endregion // Public Static Methods
  152. #region Public Instance Methods
  153. public override string ToString ()
  154. {
  155. return "TabPage: {" + Text + "}";
  156. }
  157. #endregion // Public Instance Methods
  158. #region Internal & Private Methods and Properties
  159. internal Rectangle TabBounds {
  160. get { return tab_bounds; }
  161. set { tab_bounds = value; }
  162. }
  163. internal int Row {
  164. get { return row; }
  165. set { row = value; }
  166. }
  167. private void UpdateOwner ()
  168. {
  169. if (Owner != null) {
  170. Owner.Redraw ();
  171. }
  172. }
  173. private TabControl Owner {
  174. get { return base.Parent as TabControl; }
  175. }
  176. internal void SetVisible (bool value)
  177. {
  178. base.Visible = value;
  179. }
  180. #endregion // Internal & Private Methods and Properties
  181. #region Protected Instance Methods
  182. protected override ControlCollection CreateControlsInstance ()
  183. {
  184. return new TabPageControlCollection (this);
  185. }
  186. protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
  187. {
  188. if (Owner != null && Owner.IsHandleCreated) {
  189. Rectangle display = Owner.DisplayRectangle;
  190. base.SetBoundsCore (display.X, display.Y,
  191. display.Width, display.Height,
  192. BoundsSpecified.All);
  193. } else {
  194. base.SetBoundsCore (x, y, width, height, specified);
  195. }
  196. }
  197. #endregion // Protected Instance Methods
  198. #region Events
  199. [Browsable(false)]
  200. [EditorBrowsable(EditorBrowsableState.Never)]
  201. public new event EventHandler DockChanged {
  202. add { base.DockChanged += value; }
  203. remove { base.DockChanged -= value; }
  204. }
  205. [Browsable(false)]
  206. [EditorBrowsable(EditorBrowsableState.Never)]
  207. public new event EventHandler EnabledChanged {
  208. add { base.EnabledChanged += value; }
  209. remove { base.EnabledChanged -= value; }
  210. }
  211. [Browsable(false)]
  212. [EditorBrowsable(EditorBrowsableState.Never)]
  213. public new event EventHandler TabIndexChanged {
  214. add { base.TabIndexChanged += value; }
  215. remove { base.TabIndexChanged -= value; }
  216. }
  217. [Browsable(false)]
  218. [EditorBrowsable(EditorBrowsableState.Never)]
  219. public new event EventHandler TabStopChanged {
  220. add { base.TabStopChanged += value; }
  221. remove { base.TabStopChanged -= value; }
  222. }
  223. [Browsable(false)]
  224. [EditorBrowsable(EditorBrowsableState.Never)]
  225. public new event EventHandler VisibleChanged {
  226. add { base.VisibleChanged += value; }
  227. remove { base.VisibleChanged -= value; }
  228. }
  229. #endregion // Events
  230. #if NET_2_0
  231. public new Point Location {
  232. get {
  233. return base.Location;
  234. }
  235. set {
  236. base.Location = value;
  237. }
  238. }
  239. #endif
  240. #region Class TabPageControlCollection
  241. public class TabPageControlCollection : ControlCollection {
  242. //private TabPage owner;
  243. public TabPageControlCollection (TabPage owner) : base (owner)
  244. {
  245. //this.owner = owner;
  246. }
  247. public override void Add (Control value)
  248. {
  249. base.Add (value);
  250. }
  251. }
  252. #endregion // Class TabPageControlCollection
  253. }
  254. }