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)
29 using System.ComponentModel;
30 using System.ComponentModel.Design;
32 using System.Runtime.InteropServices;
34 namespace System.Windows.Forms {
35 [DefaultProperty("BorderStyle")]
36 [DefaultEvent("Paint")]
37 [Designer ("System.Windows.Forms.Design.PanelDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
39 [Docking (DockingBehavior.Ask)]
40 [ClassInterface (ClassInterfaceType.AutoDispatch)]
43 public class Panel : ScrollableControl {
44 #region Constructors & Destructors
47 SetStyle(ControlStyles.Selectable, false);
48 SetStyle (ControlStyles.SupportsTransparentBackColor, true);
50 #endregion // Constructors & Destructors
52 #region Public Instance Properties
55 [EditorBrowsable (EditorBrowsableState.Always)]
56 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
57 public override bool AutoSize {
58 get { return base.AutoSize; }
59 set { base.AutoSize = value; }
63 [DefaultValue (AutoSizeMode.GrowOnly)]
65 public virtual AutoSizeMode AutoSizeMode {
66 get { return base.GetAutoSizeMode (); }
67 set { base.SetAutoSizeMode (value); }
71 [DefaultValue(BorderStyle.None)]
73 public BorderStyle BorderStyle {
74 get { return InternalBorderStyle; }
75 set { InternalBorderStyle = value; }
79 public new bool TabStop {
80 get { return base.TabStop; }
90 [EditorBrowsable(EditorBrowsableState.Never)]
91 public override string Text {
92 get { return base.Text; }
100 #endregion // Public Instance Properties
102 #region Protected Instance Properties
103 protected override CreateParams CreateParams {
105 return base.CreateParams;
109 protected override Size DefaultSize {
110 get { return ThemeEngine.Current.PanelDefaultSize; }
112 #endregion // Proteced Instance Properties
114 #region Public Instance Methods
115 public override string ToString ()
117 return base.ToString () + ", BorderStyle: " + BorderStyle;
119 #endregion // Public Instance Methods
121 #region Protected Instance Methods
122 protected override void OnResize(EventArgs eventargs) {
123 base.OnResize (eventargs);
127 #endregion // Protected Instance Methods
132 [EditorBrowsable (EditorBrowsableState.Always)]
133 public new event EventHandler AutoSizeChanged {
134 add { base.AutoSizeChanged += value; }
135 remove { base.AutoSizeChanged -= value; }
140 [EditorBrowsable(EditorBrowsableState.Never)]
141 public new event KeyEventHandler KeyDown {
142 add { base.KeyDown += value; }
143 remove { base.KeyDown -= value; }
147 [EditorBrowsable(EditorBrowsableState.Never)]
148 public new event KeyPressEventHandler KeyPress {
149 add { base.KeyPress += value; }
150 remove { base.KeyPress -= value; }
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public new event KeyEventHandler KeyUp {
156 add { base.KeyUp += value; }
157 remove { base.KeyUp -= value; }
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public new event EventHandler TextChanged {
163 add { base.TextChanged += value; }
164 remove { base.TextChanged -= value; }
168 #region Internal Methods
170 internal override Size GetPreferredSizeCore (Size proposedSize)
172 Size retsize = Size.Empty;
174 foreach (Control child in Controls) {
175 if (child.Dock == DockStyle.Fill) {
176 if (child.Bounds.Right > retsize.Width)
177 retsize.Width = child.Bounds.Right;
178 } else if (child.Dock != DockStyle.Top && child.Dock != DockStyle.Bottom && (child.Anchor & AnchorStyles.Right) == 0 && (child.Bounds.Right + child.Margin.Right) > retsize.Width)
179 retsize.Width = child.Bounds.Right + child.Margin.Right;
181 if (child.Dock == DockStyle.Fill) {
182 if (child.Bounds.Bottom > retsize.Height)
183 retsize.Height = child.Bounds.Bottom;
184 } else if (child.Dock != DockStyle.Left && child.Dock != DockStyle.Right && (child.Anchor & AnchorStyles.Bottom) == 0 && (child.Bounds.Bottom + child.Margin.Bottom) > retsize.Height)
185 retsize.Height = child.Bounds.Bottom + child.Margin.Bottom;