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 {
34 [ClassInterface (ClassInterfaceType.AutoDispatch)]
35 [DefaultEvent("Click")]
36 [DesignTimeVisible(false)]
37 [DefaultProperty("Text")]
38 [Designer("System.Windows.Forms.Design.TabPageDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
40 public class TabPage : Panel {
42 private int imageIndex = -1;
43 private string imageKey;
44 private string tooltip_text = String.Empty;
45 private Rectangle tab_bounds;
47 private bool use_visual_style_back_color;
50 #region Public Constructors
55 SetStyle (ControlStyles.CacheText, true);
58 public TabPage (string text) : base ()
63 #endregion // Public Constructors
65 #region .NET 2.0 Public Instance Properties
67 [EditorBrowsable (EditorBrowsableState.Never)]
68 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
69 public override bool AutoSize {
70 get { return base.AutoSize; }
71 set { base.AutoSize = value; }
76 [EditorBrowsable (EditorBrowsableState.Never)]
77 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
78 public override AutoSizeMode AutoSizeMode {
79 get { return base.AutoSizeMode; }
80 set { base.AutoSizeMode = value; }
84 [DefaultValue ("{Width=0, Height=0}")]
85 [EditorBrowsable (EditorBrowsableState.Never)]
86 public override Size MaximumSize {
87 get { return base.MaximumSize; }
88 set { base.MaximumSize = value; }
92 [EditorBrowsable (EditorBrowsableState.Never)]
93 public override Size MinimumSize {
94 get { return base.MinimumSize; }
95 set { base.MinimumSize = value; }
99 [EditorBrowsable (EditorBrowsableState.Never)]
100 public new Size PreferredSize {
101 get { return base.PreferredSize; }
104 [DefaultValue (false)]
105 public bool UseVisualStyleBackColor {
106 get { return use_visual_style_back_color; }
107 set { use_visual_style_back_color = value; }
110 public override Color BackColor {
111 get { return base.BackColor; }
112 set { use_visual_style_back_color = false; base.BackColor = value; }
116 #region Public Instance Properties
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public override AnchorStyles Anchor {
120 get { return base.Anchor; }
121 set { base.Anchor = value; }
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public override DockStyle Dock {
127 get { return base.Dock; }
128 set { base.Dock = value; }
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public new bool Enabled {
134 get { return base.Enabled; }
135 set { base.Enabled = value; }
138 [RefreshProperties (RefreshProperties.Repaint)]
140 [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
142 [TypeConverter(typeof(ImageIndexConverter))]
143 public int ImageIndex {
144 get { return imageIndex; }
146 if (imageIndex == value)
154 [RefreshProperties (RefreshProperties.Repaint)]
156 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
157 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
158 [TypeConverter (typeof (ImageKeyConverter))]
159 public string ImageKey
161 get { return imageKey; }
164 TabControl control = this.Parent as TabControl;
165 if (control != null) {
166 ImageIndex = control.ImageList.Images.IndexOfKey (imageKey);
172 [EditorBrowsable(EditorBrowsableState.Never)]
173 public new int TabIndex {
174 get { return base.TabIndex; }
175 set { base.TabIndex = value; }
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public new bool TabStop {
181 get { return base.TabStop; }
182 set { base.TabStop = value; }
185 [EditorBrowsable (EditorBrowsableState.Always)]
188 public override string Text {
189 get { return base.Text; }
191 if (value == base.Text)
200 public string ToolTipText {
201 get { return tooltip_text; }
204 value = String.Empty;
205 tooltip_text = value;
210 [EditorBrowsable(EditorBrowsableState.Never)]
211 public new bool Visible {
212 get { return base.Visible; }
213 set { /* according to MS docs we can ignore this */ }
216 #endregion // Public Instance Properties
218 #region Public Static Methods
219 public static TabPage GetTabPageOfComponent (object comp)
221 Control control = comp as Control;
224 control = control.Parent;
225 while (control != null) {
226 if (control is TabPage)
228 control = control.Parent;
230 return control as TabPage;
233 #endregion // Public Static Methods
235 #region Public Instance Methods
236 public override string ToString ()
238 return "TabPage: {" + Text + "}";
241 #endregion // Public Instance Methods
243 #region Internal & Private Methods and Properties
244 internal Rectangle TabBounds {
245 get { return tab_bounds; }
246 set { tab_bounds = value; }
254 private void UpdateOwner ()
261 private TabControl Owner {
262 get { return base.Parent as TabControl; }
265 internal void SetVisible (bool value)
267 base.Visible = value;
270 #endregion // Internal & Private Methods and Properties
272 #region Protected Instance Methods
273 protected override ControlCollection CreateControlsInstance ()
275 return new TabPageControlCollection (this);
278 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
280 if (Owner != null && Owner.IsHandleCreated) {
281 Rectangle display = Owner.DisplayRectangle;
283 base.SetBoundsCore (display.X, display.Y,
284 display.Width, display.Height,
285 BoundsSpecified.All);
287 base.SetBoundsCore (x, y, width, height, specified);
291 protected override void OnEnter (EventArgs e)
296 protected override void OnLeave (EventArgs e)
301 protected override void OnPaintBackground (PaintEventArgs e)
303 base.OnPaintBackground (e);
305 #endregion // Protected Instance Methods
309 [EditorBrowsable (EditorBrowsableState.Never)]
310 public new event EventHandler AutoSizeChanged {
311 add { base.AutoSizeChanged += value; }
312 remove { base.AutoSizeChanged -= value; }
316 [EditorBrowsable(EditorBrowsableState.Never)]
317 public new event EventHandler DockChanged {
318 add { base.DockChanged += value; }
319 remove { base.DockChanged -= value; }
323 [EditorBrowsable(EditorBrowsableState.Never)]
324 public new event EventHandler EnabledChanged {
325 add { base.EnabledChanged += value; }
326 remove { base.EnabledChanged -= value; }
330 [EditorBrowsable (EditorBrowsableState.Never)]
331 public new event EventHandler LocationChanged {
332 add { base.LocationChanged += value; }
333 remove { base.LocationChanged -= value; }
337 [EditorBrowsable(EditorBrowsableState.Never)]
338 public new event EventHandler TabIndexChanged {
339 add { base.TabIndexChanged += value; }
340 remove { base.TabIndexChanged -= value; }
344 [EditorBrowsable(EditorBrowsableState.Never)]
345 public new event EventHandler TabStopChanged {
346 add { base.TabStopChanged += value; }
347 remove { base.TabStopChanged -= value; }
351 [EditorBrowsable (EditorBrowsableState.Always)]
352 public new event EventHandler TextChanged {
353 add { base.TextChanged += value; }
354 remove { base.TextChanged -= value; }
358 [EditorBrowsable(EditorBrowsableState.Never)]
359 public new event EventHandler VisibleChanged {
360 add { base.VisibleChanged += value; }
361 remove { base.VisibleChanged -= value; }
367 [EditorBrowsable (EditorBrowsableState.Never)]
368 public new Point Location {
370 return base.Location;
374 base.Location = value;
378 #region Class TabPageControlCollection
380 public class TabPageControlCollection : ControlCollection {
382 //private TabPage owner;
384 public TabPageControlCollection (TabPage owner) : base (owner)
386 //this.owner = owner;
389 public override void Add (Control value)
394 #endregion // Class TabPageControlCollection