2 // System.Windows.Forms.GroupBox.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 // Jordi Mas i Hernandez, jordi@ximian.com
28 // Copyright (C) Novell Inc., 2004-2005
33 using System.ComponentModel;
34 using System.ComponentModel.Design;
35 using System.Runtime.InteropServices;
37 namespace System.Windows.Forms
39 [DefaultProperty("Text")]
40 [DefaultEvent("Enter")]
41 [Designer ("System.Windows.Forms.Design.GroupBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42 [ClassInterface (ClassInterfaceType.AutoDispatch)]
44 public class GroupBox : Control
46 private FlatStyle flat_style;
47 private Rectangle display_rectangle = new Rectangle ();
51 [EditorBrowsable (EditorBrowsableState.Always)]
52 public new event EventHandler AutoSizeChanged {
53 add { base.AutoSizeChanged += value; }
54 remove { base.AutoSizeChanged -= value; }
58 [EditorBrowsable(EditorBrowsableState.Advanced)]
59 public new event EventHandler Click {
60 add { base.Click += value; }
61 remove { base.Click -= value; }
65 [EditorBrowsable(EditorBrowsableState.Advanced)]
66 public new event EventHandler DoubleClick {
67 add { base.DoubleClick += value; }
68 remove { base.DoubleClick -= value; }
72 [EditorBrowsable(EditorBrowsableState.Advanced)]
73 public new event KeyEventHandler KeyDown {
74 add { base.KeyDown += value; }
75 remove { base.KeyDown -= value; }
79 [EditorBrowsable(EditorBrowsableState.Advanced)]
80 public new event KeyPressEventHandler KeyPress {
81 add { base.KeyPress += value; }
82 remove { base.KeyPress -= value; }
86 [EditorBrowsable(EditorBrowsableState.Advanced)]
87 public new event KeyEventHandler KeyUp {
88 add { base.KeyUp += value; }
89 remove { base.KeyUp -= value; }
93 [EditorBrowsable (EditorBrowsableState.Advanced)]
94 public new event MouseEventHandler MouseClick {
95 add { base.MouseClick += value; }
96 remove { base.MouseClick -= value; }
100 [EditorBrowsable (EditorBrowsableState.Advanced)]
101 public new event MouseEventHandler MouseDoubleClick {
102 add { base.MouseDoubleClick += value; }
103 remove { base.MouseDoubleClick -= value; }
107 [EditorBrowsable(EditorBrowsableState.Advanced)]
108 public new event MouseEventHandler MouseDown {
109 add { base.MouseDown += value; }
110 remove { base.MouseDown -= value; }
114 [EditorBrowsable(EditorBrowsableState.Advanced)]
115 public new event EventHandler MouseEnter {
116 add { base.MouseEnter += value; }
117 remove { base.MouseEnter -= value; }
121 [EditorBrowsable(EditorBrowsableState.Advanced)]
122 public new event EventHandler MouseLeave {
123 add { base.MouseLeave += value; }
124 remove { base.MouseLeave -= value; }
128 [EditorBrowsable(EditorBrowsableState.Advanced)]
129 public new event MouseEventHandler MouseMove {
130 add { base.MouseMove += value; }
131 remove { base.MouseMove -= value; }
135 [EditorBrowsable(EditorBrowsableState.Advanced)]
136 public new event MouseEventHandler MouseUp {
137 add { base.MouseUp += value; }
138 remove { base.MouseUp -= value; }
142 [EditorBrowsable(EditorBrowsableState.Advanced)]
143 public new event EventHandler TabStopChanged {
144 add { base.TabStopChanged += value; }
145 remove { base.TabStopChanged -= value; }
152 flat_style = FlatStyle.Standard;
154 SetStyle(ControlStyles.ContainerControl | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
155 SetStyle(ControlStyles.Selectable, false);
158 #region Public Properties
160 [EditorBrowsable(EditorBrowsableState.Advanced)]
161 public override bool AllowDrop {
162 get { return base.AllowDrop; }
163 set { base.AllowDrop = value; }
167 [EditorBrowsable (EditorBrowsableState.Always)]
168 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
169 public override bool AutoSize {
170 get { return base.AutoSize; }
171 set { base.AutoSize = value; }
175 [DefaultValue (AutoSizeMode.GrowOnly)]
177 public AutoSizeMode AutoSizeMode {
178 get { return base.GetAutoSizeMode (); }
179 set { base.SetAutoSizeMode (value); }
182 protected override CreateParams CreateParams {
183 get { return base.CreateParams; }
186 protected override Size DefaultSize {
187 get { return ThemeEngine.Current.GroupBoxDefaultSize;}
190 public override Rectangle DisplayRectangle {
192 display_rectangle.X = Padding.Left;
193 display_rectangle.Y = Font.Height + Padding.Top;
194 display_rectangle.Width = Width - Padding.Horizontal;
195 display_rectangle.Height = Height - Font.Height - Padding.Vertical;
196 return display_rectangle;
200 [DefaultValue(FlatStyle.Standard)]
201 public FlatStyle FlatStyle {
202 get { return flat_style; }
204 if (!Enum.IsDefined (typeof (FlatStyle), value))
205 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for FlatStyle", value));
207 if (flat_style == value)
216 [EditorBrowsable(EditorBrowsableState.Advanced)]
217 public new bool TabStop {
218 get { return base.TabStop; }
219 set { base.TabStop = value; }
223 public override string Text {
224 get { return base.Text; }
226 if (base.Text == value)
234 #endregion //Public Properties
236 #region Public Methods
237 protected override AccessibleObject CreateAccessibilityInstance ()
239 return new GroupBoxAccessibleObject (this);
242 protected override void OnFontChanged (EventArgs e)
244 base.OnFontChanged (e);
248 protected override void OnPaint (PaintEventArgs e)
250 ThemeEngine.Current.DrawGroupBox (e.Graphics, ClientRectangle, this);
254 protected override bool ProcessMnemonic (char charCode)
256 if (IsMnemonic(charCode, Text) == true) {
257 // Select item next in line in tab order
258 if (this.Parent != null) {
259 Parent.SelectNextControl(this, true, false, true, false);
264 return base.ProcessMnemonic (charCode);
267 protected override void ScaleControl (SizeF factor, BoundsSpecified specified)
269 base.ScaleControl (factor, specified);
272 public override string ToString()
274 return GetType ().FullName + ", Text: " + Text;
277 protected override void WndProc(ref Message m) {
278 base.WndProc (ref m);
281 #endregion Public Methods
283 [DefaultValue (false)]
284 public bool UseCompatibleTextRendering {
286 return use_compatible_text_rendering;
290 if (use_compatible_text_rendering != value) {
291 use_compatible_text_rendering = value;
293 Parent.PerformLayout (this, "UseCompatibleTextRendering");
299 #region Protected Properties
300 protected override Padding DefaultPadding {
301 get { return new Padding (3); }
305 #region Internal Methods
306 internal override Size GetPreferredSizeCore (Size proposedSize)
308 Size retsize = new Size (Padding.Left, Padding.Top);
310 foreach (Control child in Controls) {
311 if (child.Dock == DockStyle.Fill) {
312 if (child.Bounds.Right > retsize.Width)
313 retsize.Width = child.Bounds.Right;
314 } else if (child.Dock != DockStyle.Top && child.Dock != DockStyle.Bottom && (child.Bounds.Right + child.Margin.Right) > retsize.Width)
315 retsize.Width = child.Bounds.Right + child.Margin.Right;
317 if (child.Dock == DockStyle.Fill) {
318 if (child.Bounds.Bottom > retsize.Height)
319 retsize.Height = child.Bounds.Bottom;
320 } else if (child.Dock != DockStyle.Left && child.Dock != DockStyle.Right && (child.Bounds.Bottom + child.Margin.Bottom) > retsize.Height)
321 retsize.Height = child.Bounds.Bottom + child.Margin.Bottom;
324 retsize.Width += Padding.Right;
325 retsize.Height += Padding.Bottom;
327 retsize.Height += this.Font.Height;
333 #region Private Classes
334 private class GroupBoxAccessibleObject : Control.ControlAccessibleObject
336 public GroupBoxAccessibleObject (Control owner) : base (owner)