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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Jackson Harper (jackson@ximian.com)
27 using System.ComponentModel;
28 using System.ComponentModel.Design;
30 using System.Runtime.InteropServices;
32 namespace System.Windows.Forms {
35 [ClassInterface (ClassInterfaceType.AutoDispatch)]
37 [DefaultEvent("Click")]
38 [DesignTimeVisible(false)]
39 [DefaultProperty("Text")]
40 [Designer("System.Windows.Forms.Design.TabPageDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42 public class TabPage : Panel {
44 private int imageIndex = -1;
46 private string imageKey;
48 private string tooltip_text = String.Empty;
49 private Rectangle tab_bounds;
52 private bool use_visual_style_back_color;
56 #region Public Constructors
61 SetStyle (ControlStyles.CacheText, true);
64 public TabPage (string text) : base ()
69 #endregion // Public Constructors
71 #region .NET 2.0 Public Instance Properties
74 [EditorBrowsable (EditorBrowsableState.Never)]
75 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
76 public override bool AutoSize {
77 get { return base.AutoSize; }
78 set { base.AutoSize = value; }
83 [EditorBrowsable (EditorBrowsableState.Never)]
84 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
85 public override AutoSizeMode AutoSizeMode {
86 get { return base.AutoSizeMode; }
87 set { base.AutoSizeMode = value; }
91 [DefaultValue ("{Width=0, Height=0}")]
92 [EditorBrowsable (EditorBrowsableState.Never)]
93 public override Size MaximumSize {
94 get { return base.MaximumSize; }
95 set { base.MaximumSize = value; }
99 [EditorBrowsable (EditorBrowsableState.Never)]
100 public override Size MinimumSize {
101 get { return base.MinimumSize; }
102 set { base.MinimumSize = value; }
106 [EditorBrowsable (EditorBrowsableState.Never)]
107 public new Size PreferredSize {
108 get { return base.PreferredSize; }
111 [DefaultValue (false)]
112 public bool UseVisualStyleBackColor {
113 get { return use_visual_style_back_color; }
114 set { use_visual_style_back_color = value; }
117 public override Color BackColor {
118 get { return base.BackColor; }
119 set { use_visual_style_back_color = false; base.BackColor = value; }
124 #region Public Instance Properties
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public override AnchorStyles Anchor {
128 get { return base.Anchor; }
129 set { base.Anchor = value; }
133 [EditorBrowsable(EditorBrowsableState.Never)]
134 public override DockStyle Dock {
135 get { return base.Dock; }
136 set { base.Dock = value; }
140 [EditorBrowsable(EditorBrowsableState.Never)]
141 public new bool Enabled {
142 get { return base.Enabled; }
143 set { base.Enabled = value; }
147 [RefreshProperties (RefreshProperties.Repaint)]
150 [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
152 [TypeConverter(typeof(ImageIndexConverter))]
153 public int ImageIndex {
154 get { return imageIndex; }
156 if (imageIndex == value)
165 [RefreshProperties (RefreshProperties.Repaint)]
167 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
168 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
169 [TypeConverter (typeof (ImageKeyConverter))]
170 public string ImageKey
172 get { return imageKey; }
175 TabControl control = this.Parent as TabControl;
176 if (control != null) {
177 ImageIndex = control.ImageList.Images.IndexOfKey (imageKey);
185 [EditorBrowsable(EditorBrowsableState.Never)]
186 public new int TabIndex {
187 get { return base.TabIndex; }
188 set { base.TabIndex = value; }
192 [EditorBrowsable(EditorBrowsableState.Never)]
193 public new bool TabStop {
194 get { return base.TabStop; }
195 set { base.TabStop = value; }
199 [EditorBrowsable (EditorBrowsableState.Always)]
203 public override string Text {
204 get { return base.Text; }
206 if (value == base.Text)
215 public string ToolTipText {
216 get { return tooltip_text; }
219 value = String.Empty;
220 tooltip_text = value;
225 [EditorBrowsable(EditorBrowsableState.Never)]
226 public new bool Visible {
227 get { return base.Visible; }
228 set { /* according to MS docs we can ignore this */ }
231 #endregion // Public Instance Properties
233 #region Public Static Methods
234 public static TabPage GetTabPageOfComponent (object comp)
236 Control control = comp as Control;
239 control = control.Parent;
240 while (control != null) {
241 if (control is TabPage)
243 control = control.Parent;
245 return control as TabPage;
248 #endregion // Public Static Methods
250 #region Public Instance Methods
251 public override string ToString ()
253 return "TabPage: {" + Text + "}";
256 #endregion // Public Instance Methods
258 #region Internal & Private Methods and Properties
259 internal Rectangle TabBounds {
260 get { return tab_bounds; }
261 set { tab_bounds = value; }
269 private void UpdateOwner ()
276 private TabControl Owner {
277 get { return base.Parent as TabControl; }
280 internal void SetVisible (bool value)
282 base.Visible = value;
285 #endregion // Internal & Private Methods and Properties
287 #region Protected Instance Methods
288 protected override ControlCollection CreateControlsInstance ()
290 return new TabPageControlCollection (this);
293 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
295 if (Owner != null && Owner.IsHandleCreated) {
296 Rectangle display = Owner.DisplayRectangle;
298 base.SetBoundsCore (display.X, display.Y,
299 display.Width, display.Height,
300 BoundsSpecified.All);
302 base.SetBoundsCore (x, y, width, height, specified);
307 protected override void OnEnter (EventArgs e)
312 protected override void OnLeave (EventArgs e)
317 protected override void OnPaintBackground (PaintEventArgs e)
319 base.OnPaintBackground (e);
322 #endregion // Protected Instance Methods
327 [EditorBrowsable (EditorBrowsableState.Never)]
328 public new event EventHandler AutoSizeChanged {
329 add { base.AutoSizeChanged += value; }
330 remove { base.AutoSizeChanged -= value; }
335 [EditorBrowsable(EditorBrowsableState.Never)]
336 public new event EventHandler DockChanged {
337 add { base.DockChanged += value; }
338 remove { base.DockChanged -= value; }
342 [EditorBrowsable(EditorBrowsableState.Never)]
343 public new event EventHandler EnabledChanged {
344 add { base.EnabledChanged += value; }
345 remove { base.EnabledChanged -= value; }
350 [EditorBrowsable (EditorBrowsableState.Never)]
351 public new event EventHandler LocationChanged {
352 add { base.LocationChanged += value; }
353 remove { base.LocationChanged -= value; }
358 [EditorBrowsable(EditorBrowsableState.Never)]
359 public new event EventHandler TabIndexChanged {
360 add { base.TabIndexChanged += value; }
361 remove { base.TabIndexChanged -= value; }
365 [EditorBrowsable(EditorBrowsableState.Never)]
366 public new event EventHandler TabStopChanged {
367 add { base.TabStopChanged += value; }
368 remove { base.TabStopChanged -= value; }
373 [EditorBrowsable (EditorBrowsableState.Always)]
374 public new event EventHandler TextChanged {
375 add { base.TextChanged += value; }
376 remove { base.TextChanged -= value; }
381 [EditorBrowsable(EditorBrowsableState.Never)]
382 public new event EventHandler VisibleChanged {
383 add { base.VisibleChanged += value; }
384 remove { base.VisibleChanged -= value; }
391 [EditorBrowsable (EditorBrowsableState.Never)]
392 public new Point Location {
394 return base.Location;
398 base.Location = value;
402 #region Class TabPageControlCollection
406 public class TabPageControlCollection : ControlCollection {
408 //private TabPage owner;
410 public TabPageControlCollection (TabPage owner) : base (owner)
412 //this.owner = owner;
415 public override void Add (Control value)
420 #endregion // Class TabPageControlCollection