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-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32 using System.ComponentModel.Design.Serialization;
33 using System.Collections;
34 using System.Runtime.InteropServices;
35 using System.Threading;
37 namespace System.Windows.Forms {
38 [DesignerCategory("Form")]
39 [DesignTimeVisible(false)]
40 [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
41 [DefaultEvent("Load")]
43 [ClassInterface (ClassInterfaceType.AutoDispatch)]
44 [InitializationEvent ("Load")]
46 [ToolboxItemFilter ("System.Windows.Forms.Control.TopLevel")]
49 public class Form : ContainerControl {
50 #region Local Variables
51 internal bool closing;
53 FormBorderStyle form_border_style;
54 private bool is_active;
55 private bool autoscale;
56 private Size clientsize_set;
57 private Size autoscale_base_size;
58 private bool allow_transparency;
59 private static Icon default_icon;
60 internal bool is_modal;
61 internal FormWindowState window_state;
62 private bool control_box;
63 private bool minimize_box;
64 private bool maximize_box;
65 private bool help_button;
66 private bool show_in_taskbar;
68 private IButtonControl accept_button;
69 private IButtonControl cancel_button;
70 private DialogResult dialog_result;
71 private FormStartPosition start_position;
73 private Form.ControlCollection owned_forms;
74 private MdiClient mdi_container;
75 internal InternalWindowManager window_manager;
76 private Form mdi_parent;
77 private bool key_preview;
78 private MainMenu menu;
80 private Size maximum_size;
81 private Size minimum_size;
82 private SizeGripStyle size_grip_style;
83 private SizeGrip size_grip;
84 private Rectangle maximized_bounds;
85 private Rectangle default_maximized_bounds;
86 private double opacity;
87 internal ApplicationContext context;
88 Color transparency_key;
89 internal MenuTracker active_tracker;
90 private bool is_loaded;
91 internal int is_changing_visible_state;
92 internal bool has_been_visible;
93 private bool shown_raised; // The shown event is only raised once
94 private bool is_clientsize_set;
95 internal bool suppress_closing_events;
98 private MenuStrip main_menu_strip;
99 private bool show_icon = true;
100 private bool right_to_left_layout;
102 #endregion // Local Variables
104 #region Private & Internal Methods
107 default_icon = Locale.GetResource("mono.ico") as Icon;
110 internal bool IsActive {
115 if (is_active == value || IsRecreating) {
121 Application.AddForm (this);
122 OnActivated (EventArgs.Empty);
124 OnDeactivate (EventArgs.Empty);
129 // warning: this is only hooked up when an mdi container is created.
130 private void ControlAddedHandler (object sender, ControlEventArgs e)
132 if (mdi_container != null) {
133 mdi_container.SendToBack ();
137 // Convenience method for fire BOTH OnClosing and OnFormClosing events
138 // Returns the value of Cancel, so true means the Close was cancelled,
139 // and you shouldn't close the form.
140 internal bool FireClosingEvents (CloseReason reason)
142 CancelEventArgs cea = new CancelEventArgs ();
143 this.OnClosing (cea);
146 FormClosingEventArgs fcea = new FormClosingEventArgs (reason, cea.Cancel);
147 this.OnFormClosing (fcea);
155 internal override Size GetPreferredSizeCore (Size proposedSize)
157 Size retsize = Size.Empty;
159 foreach (Control child in Controls) {
160 if (child.Dock == DockStyle.Fill) {
161 if (child.Bounds.Right > retsize.Width)
162 retsize.Width = child.Bounds.Right;
164 else if (child.Dock != DockStyle.Top && child.Dock != DockStyle.Bottom && (child.Bounds.Right + child.Margin.Right) > retsize.Width)
165 retsize.Width = child.Bounds.Right + child.Margin.Right;
167 if (child.Dock == DockStyle.Fill) {
168 if (child.Bounds.Bottom > retsize.Height)
169 retsize.Height = child.Bounds.Bottom;
171 else if (child.Dock != DockStyle.Left && child.Dock != DockStyle.Right && (child.Bounds.Bottom + child.Margin.Bottom) > retsize.Height)
172 retsize.Height = child.Bounds.Bottom + child.Margin.Bottom;
175 return SizeFromClientSize (retsize);
178 [EditorBrowsable (EditorBrowsableState.Advanced)]
179 protected override Rectangle GetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
181 // Never change the Form's location
182 specified &= ~BoundsSpecified.Location;
184 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth))
185 bounds.Width = (int)Math.Round (bounds.Width * factor.Width);
186 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight))
187 bounds.Height = (int)Math.Round (bounds.Height * factor.Height);
189 Size size = ClientSizeFromSize (bounds.Size);
191 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth))
192 bounds.Width -= (int)((bounds.Width - size.Width) * (factor.Width - 1));
193 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight))
194 bounds.Height -= (int)((bounds.Height - size.Height) * (factor.Height - 1));
199 protected override bool ProcessMnemonic (char charCode)
201 return base.ProcessMnemonic (charCode);
204 [EditorBrowsable (EditorBrowsableState.Advanced)]
205 protected override void ScaleControl (SizeF factor, BoundsSpecified specified)
207 Rectangle new_bounds = GetScaledBounds (bounds, factor, specified);
209 SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, specified);
213 internal void OnActivatedInternal ()
215 OnActivated (EventArgs.Empty);
218 internal void OnDeactivateInternal ()
220 OnDeactivate (EventArgs.Empty);
223 internal override void UpdateWindowText ()
225 if (!IsHandleCreated) {
230 /* we need to call .SetWindowStyle here instead of just .Text
231 because the presence/absence of Text (== "" or not) can cause
232 other window style things to appear/disappear */
233 XplatUI.SetWindowStyle (window.Handle, CreateParams);
236 XplatUI.Text (Handle, Text.Replace (Environment.NewLine, string.Empty));
239 internal void SelectActiveControl ()
241 if (this.IsMdiContainer) {
242 mdi_container.SendFocusToActiveChild ();
246 if (this.ActiveControl == null) {
249 // This visible hack is to work around CanSelect always being false if one of the parents
250 // is not visible; and we by default create Form invisible...
251 visible = this.is_visible;
252 this.is_visible = true;
254 if (SelectNextControl (this, true, true, true, true) == false) {
258 this.is_visible = visible;
260 Select (ActiveControl);
264 private new void UpdateSizeGripVisible ()
266 // Following link explains when to show size grip:
267 // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=138687&SiteID=1
268 // if SizeGripStyle.Auto, only shown if form is shown using ShowDialog and is sizable
269 // if SizeGripStyle.Show, only shown if form is sizable
273 switch (size_grip_style) {
274 case SizeGripStyle.Auto:
275 show = is_modal && (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
277 case SizeGripStyle.Hide:
280 case SizeGripStyle.Show:
281 show = (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
286 if (size_grip != null && size_grip.Visible)
287 size_grip.Visible = false;
289 if (size_grip == null) {
290 size_grip = new SizeGrip (this);
291 size_grip.Virtual = true;
292 size_grip.FillBackground = false;
294 size_grip.Visible = true;
298 internal void ChangingParent (Control new_parent)
304 bool recreate_necessary = false;
306 if (new_parent == null) {
307 recreate_necessary = window_manager is FormWindowManager;
308 window_manager = null;
309 } else if (new_parent is MdiClient) {
310 window_manager = new MdiWindowManager (this, (MdiClient) new_parent);
312 window_manager = new FormWindowManager (this);
313 recreate_necessary = true;
316 if (recreate_necessary) {
317 if (IsHandleCreated) {
318 if (new_parent.IsHandleCreated) {
325 if (IsHandleCreated) {
326 IntPtr new_handle = IntPtr.Zero;
327 if (new_parent != null && new_parent.IsHandleCreated) {
328 new_handle = new_parent.Handle;
330 XplatUI.SetParent (Handle, new_handle);
334 if (window_manager != null) {
335 window_manager.UpdateWindowState (window_state, window_state, true);
339 internal override bool FocusInternal (bool skip_check)
342 // MS always creates handles when Focus () is called for mdi clients.
343 if (!IsHandleCreated)
346 return base.FocusInternal (skip_check);
348 #endregion // Private & Internal Methods
350 #region Public Classes
354 public new class ControlCollection : Control.ControlCollection {
357 public ControlCollection(Form owner) : base(owner) {
358 this.form_owner = owner;
361 public override void Add(Control value) {
362 if (Contains (value))
365 ((Form)value).owner=form_owner;
368 public override void Remove(Control value) {
369 ((Form)value).owner = null;
373 #endregion // Public Classes
375 #region Public Constructor & Destructor
378 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
381 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
382 allow_transparency = false;
385 dialog_result = DialogResult.None;
386 start_position = FormStartPosition.WindowsDefaultLocation;
387 form_border_style = FormBorderStyle.Sizable;
388 window_state = FormWindowState.Normal;
393 minimum_size = Size.Empty;
394 maximum_size = Size.Empty;
395 clientsize_set = Size.Empty;
400 show_in_taskbar = true;
403 size_grip_style = SizeGripStyle.Auto;
404 maximized_bounds = Rectangle.Empty;
405 default_maximized_bounds = Rectangle.Empty;
406 owned_forms = new Form.ControlCollection(this);
407 transparency_key = Color.Empty;
408 InternalClientSize = new Size (this.Width - (SystemInformation.FrameBorderSize.Width * 2), this.Height - (SystemInformation.FrameBorderSize.Height * 2) - SystemInformation.CaptionHeight);
410 #endregion // Public Constructor & Destructor
412 #region Public Static Properties
414 public static Form ActiveForm {
418 active = FromHandle(XplatUI.GetActive());
420 if (active != null) {
421 if ( !(active is Form)) {
424 parent = active.Parent;
425 while (parent != null) {
426 if (parent is Form) {
429 parent = parent.Parent;
439 #endregion // Public Static Properties
441 #region Public Instance Properties
443 public IButtonControl AcceptButton {
445 return accept_button;
449 if (accept_button != null)
450 accept_button.NotifyDefault (false);
452 accept_button = value;
453 if (accept_button != null)
454 accept_button.NotifyDefault (true);
456 CheckAcceptButton ();
461 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
462 public bool AllowTransparency {
464 return allow_transparency;
468 if (value == allow_transparency) {
472 allow_transparency = value;
475 if (IsHandleCreated) {
476 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
477 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
480 UpdateStyles(); // Remove the WS_EX_LAYERED style
488 [EditorBrowsable (EditorBrowsableState.Never)]
489 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
490 [Obsolete ("This property has been deprecated in favor of AutoScaleMode.")]
494 [MWFCategory("Layout")]
495 public bool AutoScale {
506 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
507 [EditorBrowsable(EditorBrowsableState.Never)]
509 [EditorBrowsable(EditorBrowsableState.Advanced)]
513 public virtual Size AutoScaleBaseSize {
515 return autoscale_base_size;
519 autoscale_base_size = value;
524 public override bool AutoScroll {
526 return base.AutoScroll;
529 base.AutoScroll = value;
533 internal bool ShouldSerializeAutoScroll ()
535 return this.AutoScroll != false;
540 [EditorBrowsable (EditorBrowsableState.Always)]
541 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
542 public override bool AutoSize {
543 get { return base.AutoSize; }
545 if (base.AutoSize != value) {
546 base.AutoSize = value;
547 PerformLayout (this, "AutoSize");
552 internal bool ShouldSerializeAutoSize ()
554 return this.AutoSize != false;
559 [DefaultValue (AutoSizeMode.GrowOnly)]
560 public AutoSizeMode AutoSizeMode {
561 get { return base.GetAutoSizeMode (); }
563 if (base.GetAutoSizeMode () != value) {
564 if (!Enum.IsDefined (typeof (AutoSizeMode), value))
565 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for AutoSizeMode", value));
567 base.SetAutoSizeMode (value);
568 PerformLayout (this, "AutoSizeMode");
574 [EditorBrowsable (EditorBrowsableState.Always)]
575 public override AutoValidate AutoValidate {
576 get { return base.AutoValidate; }
577 set { base.AutoValidate = value; }
581 public override Color BackColor {
583 /* we don't let parents override our
584 default background color for forms.
585 this fixes the default color for mdi
587 if (background_color.IsEmpty)
588 return DefaultBackColor;
590 return background_color;
593 base.BackColor = value;
598 public IButtonControl CancelButton {
600 return cancel_button;
604 cancel_button = value;
605 if (cancel_button != null && cancel_button.DialogResult == DialogResult.None)
606 cancel_button.DialogResult = DialogResult.Cancel;
610 // new property so we can change the DesignerSerializationVisibility
611 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
613 public new Size ClientSize {
614 get { return base.ClientSize; }
616 is_clientsize_set = true;
617 base.ClientSize = value;
622 [MWFCategory("Window Style")]
623 public bool ControlBox {
629 if (control_box != value) {
637 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
638 public Rectangle DesktopBounds {
640 return new Rectangle(Location, Size);
649 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
650 public Point DesktopLocation {
661 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
662 public DialogResult DialogResult {
664 return dialog_result;
668 if (value < DialogResult.None || value > DialogResult.No)
669 throw new InvalidEnumArgumentException ("value", (int) value,
670 typeof (DialogResult));
672 dialog_result = value;
673 closing = (dialog_result != DialogResult.None && is_modal);
677 [DefaultValue(FormBorderStyle.Sizable)]
679 [MWFCategory("Appearance")]
680 public FormBorderStyle FormBorderStyle {
682 return form_border_style;
685 form_border_style = value;
687 if (window_manager == null) {
688 if (IsHandleCreated) {
689 XplatUI.SetBorderStyle(window.Handle, form_border_style);
692 window_manager.UpdateBorderStyle (value);
695 Size current_client_size = ClientSize;
698 if (this.IsHandleCreated) {
699 this.Size = InternalSizeFromClientSize (current_client_size);
700 XplatUI.InvalidateNC (this.Handle);
701 } else if (is_clientsize_set) {
702 this.Size = InternalSizeFromClientSize (current_client_size);
707 [DefaultValue(false)]
708 [MWFCategory("Window Style")]
709 public bool HelpButton {
715 if (help_button != value) {
724 [MWFCategory("Window Style")]
734 if (IsHandleCreated) {
735 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
741 internal bool ShouldSerializeIcon ()
743 return this.Icon != default_icon;
747 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
748 public bool IsMdiChild {
750 return mdi_parent != null;
754 [DefaultValue(false)]
755 [MWFCategory("Window Style")]
756 public bool IsMdiContainer {
758 return mdi_container != null;
762 if (value && mdi_container == null) {
763 mdi_container = new MdiClient ();
764 Controls.Add(mdi_container);
765 ControlAdded += new ControlEventHandler (ControlAddedHandler);
766 mdi_container.SendToBack ();
767 mdi_container.SetParentText (true);
768 } else if (!value && mdi_container != null) {
769 Controls.Remove(mdi_container);
770 mdi_container = null;
776 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
777 public Form ActiveMdiChild {
781 return (Form) mdi_container.ActiveMdiChild;
786 [EditorBrowsable(EditorBrowsableState.Advanced)]
787 public bool IsRestrictedWindow {
793 [DefaultValue(false)]
794 public bool KeyPreview {
805 [DefaultValue (null)]
806 [TypeConverter (typeof (ReferenceConverter))]
807 public MenuStrip MainMenuStrip {
808 get { return this.main_menu_strip; }
810 if (this.main_menu_strip != value) {
811 this.main_menu_strip = value;
812 this.main_menu_strip.RefreshMdiItems ();
817 [EditorBrowsable (EditorBrowsableState.Never)]
819 public new Padding Margin {
820 get { return base.Margin; }
821 set { base.Margin = value; }
826 [MWFCategory("Window Style")]
827 public bool MaximizeBox {
832 if (maximize_box != value) {
833 maximize_box = value;
839 [DefaultValue(typeof (Size),"0, 0")]
841 [RefreshProperties(RefreshProperties.Repaint)]
842 [MWFCategory("Layout")]
853 if (maximum_size != value) {
854 maximum_size = value;
855 OnMaximumSizeChanged(EventArgs.Empty);
856 if (IsHandleCreated) {
857 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
864 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
865 public Form[] MdiChildren {
867 if (mdi_container != null)
868 return mdi_container.MdiChildren;
875 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
876 public Form MdiParent {
882 if (value != null && !value.IsMdiContainer)
883 throw new ArgumentException ("Form that was specified to be "
884 + "the MdiParent for this form is not an MdiContainer.");
886 if (mdi_parent != null) {
887 mdi_parent.MdiContainer.Controls.Remove (this);
892 if (window_manager == null) {
893 window_manager = new MdiWindowManager (this, mdi_parent.MdiContainer);
896 mdi_parent.MdiContainer.Controls.Add (this);
897 mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
901 } else if (mdi_parent != null) {
904 // Create a new window manager
905 window_manager = null;
906 FormBorderStyle = form_border_style;
911 is_toplevel = mdi_parent == null;
915 internal MenuTracker ActiveTracker {
916 get { return active_tracker; }
918 if (value == active_tracker)
921 Capture = value != null;
922 active_tracker = value;
926 internal MdiClient MdiContainer {
927 get { return mdi_container; }
930 internal InternalWindowManager WindowManager {
931 get { return window_manager; }
936 [TypeConverter (typeof (ReferenceConverter))]
939 [MWFCategory("Window Style")]
940 public MainMenu Menu {
949 if (menu != null && !IsMdiChild) {
952 if (IsHandleCreated) {
953 XplatUI.SetMenu (window.Handle, menu);
956 if (clientsize_set != Size.Empty) {
957 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
959 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
960 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
969 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
970 [EditorBrowsable(EditorBrowsableState.Advanced)]
971 public MainMenu MergedMenu {
973 if (!IsMdiChild || window_manager == null)
975 return ((MdiWindowManager) window_manager).MergedMenu;
979 // This is the menu in display and being used because of merging this can
980 // be different then the menu that is actually assosciated with the form
981 internal MainMenu ActiveMenu {
986 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
987 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
988 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
989 return wm.MaximizedMenu;
992 Form amc = ActiveMdiChild;
993 if (amc == null || amc.Menu == null)
995 return amc.MergedMenu;
999 internal MdiWindowManager ActiveMaximizedMdiChild {
1001 Form child = ActiveMdiChild;
1004 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
1006 return (MdiWindowManager) child.WindowManager;
1010 [DefaultValue(true)]
1011 [MWFCategory("Window Style")]
1012 public bool MinimizeBox {
1014 return minimize_box;
1017 if (minimize_box != value) {
1018 minimize_box = value;
1025 [DefaultValue("{Width=0, Height=0}")]
1028 [RefreshProperties(RefreshProperties.Repaint)]
1029 [MWFCategory("Layout")]
1036 return minimum_size;
1040 if (minimum_size != value) {
1041 minimum_size = value;
1043 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
1044 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
1048 OnMinimumSizeChanged(EventArgs.Empty);
1049 if (IsHandleCreated) {
1050 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1057 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1065 [TypeConverter(typeof(OpacityConverter))]
1066 [MWFCategory("Window Style")]
1067 public double Opacity {
1069 if (IsHandleCreated) {
1070 if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
1071 return XplatUI.GetWindowTransparency (Handle);
1086 AllowTransparency = true;
1088 if (IsHandleCreated) {
1090 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
1091 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
1098 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1099 public Form[] OwnedForms {
1103 form_list = new Form[owned_forms.Count];
1105 for (int i=0; i<owned_forms.Count; i++) {
1106 form_list[i] = (Form)owned_forms[i];
1114 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1121 if (owner != value) {
1122 if (owner != null) {
1123 owner.RemoveOwnedForm(this);
1127 owner.AddOwnedForm(this);
1128 if (IsHandleCreated) {
1129 if (owner != null && owner.IsHandleCreated) {
1130 XplatUI.SetOwner(this.window.Handle, owner.window.Handle);
1132 XplatUI.SetOwner(this.window.Handle, IntPtr.Zero);
1140 [Localizable (true)]
1141 [DefaultValue (false)]
1142 public virtual bool RightToLeftLayout {
1143 get { return this.right_to_left_layout; }
1144 set { this.right_to_left_layout = value; }
1147 [DefaultValue (true)]
1148 public bool ShowIcon {
1149 get { return this.show_icon; }
1151 if (this.show_icon != value ) {
1152 this.show_icon = value;
1155 if (IsHandleCreated) {
1156 XplatUI.SetIcon (this.Handle, value == true ? this.Icon : null);
1157 XplatUI.InvalidateNC (this.Handle);
1164 [DefaultValue(true)]
1165 [MWFCategory("Window Style")]
1166 public bool ShowInTaskbar {
1168 return show_in_taskbar;
1171 if (show_in_taskbar != value) {
1172 show_in_taskbar = value;
1173 if (IsHandleCreated) {
1181 // new property so we can set the DesignerSerializationVisibility
1182 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1183 [Localizable(false)]
1184 public new Size Size {
1185 get { return base.Size; }
1186 set { base.Size = value; }
1189 [DefaultValue(SizeGripStyle.Auto)]
1190 [MWFCategory("Window Style")]
1191 public SizeGripStyle SizeGripStyle {
1193 return size_grip_style;
1197 size_grip_style = value;
1198 UpdateSizeGripVisible ();
1202 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
1204 [MWFCategory("Layout")]
1205 public FormStartPosition StartPosition {
1207 return start_position;
1211 start_position = value;
1215 // new property so we can set EditorBrowsable to never
1217 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1218 [EditorBrowsable(EditorBrowsableState.Never)]
1219 public new int TabIndex {
1220 get { return base.TabIndex; }
1221 set { base.TabIndex = value; }
1226 [DefaultValue (true)]
1227 [DispIdAttribute (-516)]
1228 [EditorBrowsable(EditorBrowsableState.Never)]
1229 public new bool TabStop {
1230 get { return base.TabStop; }
1231 set { base.TabStop = value; }
1236 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1237 [EditorBrowsable(EditorBrowsableState.Advanced)]
1238 public bool TopLevel {
1240 return GetTopLevel();
1244 if (!value && IsMdiContainer)
1245 throw new ArgumentException ("MDI Container forms must be top level.");
1250 [DefaultValue(false)]
1251 [MWFCategory("Window Style")]
1252 public bool TopMost {
1258 if (topmost != value) {
1260 if (IsHandleCreated)
1261 XplatUI.SetTopmost(window.Handle, value);
1266 [MWFCategory("Window Style")]
1267 public Color TransparencyKey {
1269 return transparency_key;
1273 transparency_key = value;
1275 AllowTransparency = true;
1277 if (IsHandleCreated && (XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
1278 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
1282 internal bool ShouldSerializeTransparencyKey ()
1284 return this.TransparencyKey != Color.Empty;
1287 [DefaultValue(FormWindowState.Normal)]
1288 [MWFCategory("Layout")]
1289 public FormWindowState WindowState {
1291 // Don't actually rely on the WM until we've been shown
1292 if (IsHandleCreated && shown_raised) {
1294 if (window_manager != null)
1295 return window_manager.GetWindowState ();
1297 FormWindowState new_state = XplatUI.GetWindowState(Handle);
1298 if (new_state != (FormWindowState)(-1))
1299 window_state = new_state;
1302 return window_state;
1306 FormWindowState old_state = window_state;
1307 window_state = value;
1308 if (IsHandleCreated && shown_raised) {
1310 if (window_manager != null) {
1311 window_manager.SetWindowState (old_state, value);
1315 XplatUI.SetWindowState(Handle, value);
1320 #endregion // Public Instance Properties
1322 #region Protected Instance Properties
1323 protected override CreateParams CreateParams {
1325 CreateParams cp = new CreateParams ();
1328 cp.Caption = Text.Replace (Environment.NewLine, string.Empty);
1330 cp.ClassName = XplatUI.DefaultClassName;
1335 cp.Parent = IntPtr.Zero;
1336 cp.menu = ActiveMenu;
1339 if (((Parent != null || !TopLevel) && !IsMdiChild)) {
1340 // Parented forms and non-toplevel forms always gets the specified location, no matter what
1344 switch (start_position) {
1345 case FormStartPosition.Manual:
1349 case FormStartPosition.CenterScreen:
1351 cp.X = Math.Max ((MdiParent.mdi_container.ClientSize.Width - Width) / 2, 0);
1352 cp.Y = Math.Max ((MdiParent.mdi_container.ClientSize.Height - Height) / 2, 0);
1354 cp.X = Math.Max ((Screen.PrimaryScreen.WorkingArea.Width - Width) / 2, 0);
1355 cp.Y = Math.Max ((Screen.PrimaryScreen.WorkingArea.Height - Height) / 2, 0);
1358 case FormStartPosition.CenterParent:
1359 case FormStartPosition.WindowsDefaultBounds:
1360 case FormStartPosition.WindowsDefaultLocation:
1361 cp.X = int.MinValue;
1362 cp.Y = int.MinValue;
1369 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN);
1371 cp.WindowStyle |= WindowStyles.WS_CLIPSIBLINGS;
1374 if (Parent != null && Parent.IsHandleCreated) {
1375 cp.Parent = Parent.Handle;
1376 cp.Style |= (int) WindowStyles.WS_CHILD;
1380 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
1381 if (Parent != null) {
1382 cp.Parent = Parent.Handle;
1385 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
1387 switch (FormBorderStyle) {
1388 case FormBorderStyle.None:
1390 case FormBorderStyle.FixedToolWindow:
1391 case FormBorderStyle.SizableToolWindow:
1392 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
1395 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1400 switch (FormBorderStyle) {
1401 case FormBorderStyle.Fixed3D: {
1402 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1403 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
1407 case FormBorderStyle.FixedDialog: {
1408 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1409 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1413 case FormBorderStyle.FixedSingle: {
1414 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1418 case FormBorderStyle.FixedToolWindow: {
1419 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1420 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1424 case FormBorderStyle.Sizable: {
1425 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1429 case FormBorderStyle.SizableToolWindow: {
1430 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1431 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1435 case FormBorderStyle.None: {
1441 switch(window_state) {
1442 case FormWindowState.Maximized: {
1443 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1447 case FormWindowState.Minimized: {
1448 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1454 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1457 if (ShowInTaskbar) {
1458 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1462 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1466 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1470 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1474 if (!this.show_icon) {
1475 cp.ExStyle |= (int)WindowExStyles.WS_EX_DLGMODALFRAME;
1478 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTROLPARENT;
1480 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1481 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1485 //don't set WS_VISIBLE if we're changing visibility. We can't create forms visible,
1486 //since we have to set the owner before making the form visible
1487 //(otherwise Win32 will do strange things with task bar icons).
1488 //The problem is that we set the internal is_visible to true before creating the control,
1489 //so is_changing_visible_state is the only way of determining if we're
1490 //in the process of creating the form due to setting Visible=true.
1491 //This works because SetVisibleCore explicitly makes the form visibile afterwards anyways.
1493 //only do this when on Windows, since X behaves weirdly otherwise
1494 //modal windows appear below their parent/owner/ancestor.
1495 //(confirmed on several window managers, so it's not a wm bug).
1496 bool is_unix = ((int) Environment.OSVersion.Platform) == 128 || ((int) Environment.OSVersion.Platform == 4);
1497 if ((VisibleInternal && (is_changing_visible_state == 0 || is_unix)) || this.IsRecreating)
1498 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1500 if (opacity < 1.0 || TransparencyKey != Color.Empty) {
1501 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1504 if (!is_enabled && context == null) {
1505 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1508 if (!ControlBox && Text == string.Empty) {
1509 cp.WindowStyle &= ~WindowStyles.WS_DLGFRAME;
1512 // Fake the window styles for mdi and parented forms
1513 if (cp.HasWindowManager && !cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW)) {
1514 // Remove all styles but WS_VISIBLE.
1515 cp.WindowStyle &= WindowStyles.WS_VISIBLE;
1516 // Set styles that enables us to use the window manager.
1517 cp.WindowStyle |= WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS;
1525 protected override ImeMode DefaultImeMode {
1527 return ImeMode.NoControl;
1531 protected override Size DefaultSize {
1533 return new Size (300, 300);
1537 protected Rectangle MaximizedBounds {
1539 if (maximized_bounds != Rectangle.Empty) {
1540 return maximized_bounds;
1542 return default_maximized_bounds;
1546 maximized_bounds = value;
1547 OnMaximizedBoundsChanged(EventArgs.Empty);
1548 if (IsHandleCreated) {
1549 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1558 [MonoTODO ("Implemented for Win32, needs X11 implementation")]
1561 virtual bool ShowWithoutActivation {
1562 get { return false; }
1564 #endregion // Protected Instance Properties
1566 #region Public Static Methods
1568 [EditorBrowsable(EditorBrowsableState.Never)]
1569 [Obsolete ("This method has been deprecated. Use AutoScaleDimensions instead")]
1571 [EditorBrowsable(EditorBrowsableState.Advanced)]
1573 public static SizeF GetAutoScaleSize (Font font)
1575 return XplatUI.GetAutoScaleSize(font);
1578 #endregion // Public Static Methods
1580 #region Public Instance Methods
1581 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1584 // The following constants come from the dotnet mailing list
1585 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1587 // The magic number is "Its almost the length
1588 // of the string with a smattering added in
1589 // for compat with earlier code".
1592 string magic_string = "The quick brown fox jumped over the lazy dog.";
1593 double magic_number = 44.549996948242189;
1594 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1596 return new SizeF (width, font.Height);
1599 public void Activate ()
1603 if (IsHandleCreated) {
1605 MdiParent.ActivateMdiChild (this);
1606 } else if (IsMdiContainer) {
1607 mdi_container.SendFocusToActiveChild ();
1609 XplatUI.Activate(window.Handle);
1614 public void AddOwnedForm(Form ownedForm) {
1615 if (!owned_forms.Contains(ownedForm)) {
1616 owned_forms.Add(ownedForm);
1618 ownedForm.Owner = this;
1621 public void Close () {
1625 if (!IsHandleCreated)
1628 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1633 public void LayoutMdi(MdiLayout value) {
1634 if (mdi_container != null) {
1635 mdi_container.LayoutMdi(value);
1639 public void RemoveOwnedForm(Form ownedForm) {
1640 owned_forms.Remove(ownedForm);
1643 public void SetDesktopBounds(int x, int y, int width, int height) {
1644 DesktopBounds = new Rectangle(x, y, width, height);
1647 public void SetDesktopLocation(int x, int y) {
1648 DesktopLocation = new Point(x, y);
1652 public void Show (IWin32Window owner)
1657 this.Owner = Control.FromHandle (owner.Handle).TopLevelControl as Form;
1660 throw new InvalidOperationException ("The 'owner' cannot be the form being shown.");
1662 if (TopLevelControl != this) {
1663 throw new InvalidOperationException ("Forms that are not top level"
1664 + " forms cannot be displayed as a modal dialog. Remove the"
1665 + " form from any parent form before calling Show.");
1672 public DialogResult ShowDialog() {
1673 return ShowDialog (null);
1676 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1679 IntPtr capture_window;
1681 Form owner_to_be = null;
1683 if ((ownerWin32 == null) && (Application.MWFThread.Current.Context != null)) {
1684 IntPtr active = XplatUI.GetActive ();
1685 if (active != IntPtr.Zero) {
1686 ownerWin32 = Control.FromHandle (active) as Form;
1690 if (ownerWin32 != null) {
1691 Control c = Control.FromHandle (ownerWin32.Handle);
1693 owner_to_be = c.TopLevelControl as Form;
1696 if (owner_to_be == this) {
1697 throw new ArgumentException ("Forms cannot own themselves or their owners.", "owner");
1701 throw new InvalidOperationException ("The form is already displayed as a modal dialog.");
1705 throw new InvalidOperationException ("Forms that are already "
1706 + " visible cannot be displayed as a modal dialog. Set the"
1707 + " form's visible property to false before calling"
1712 throw new InvalidOperationException ("Forms that are not enabled"
1713 + " cannot be displayed as a modal dialog. Set the form's"
1714 + " enabled property to true before calling ShowDialog.");
1717 if (TopLevelControl != this) {
1718 throw new InvalidOperationException ("Forms that are not top level"
1719 + " forms cannot be displayed as a modal dialog. Remove the"
1720 + " form from any parent form before calling ShowDialog.");
1723 if (owner_to_be != null)
1724 owner = owner_to_be;
1727 // Can't do this, will screw us in the modal loop
1728 form_parent_window.Parent = this.owner;
1731 // Release any captures
1732 XplatUI.GrabInfo(out capture_window, out confined, out area);
1733 if (capture_window != IntPtr.Zero) {
1734 XplatUI.UngrabWindow(capture_window);
1738 // Commented out; we instead let the Visible=true inside the runloop create the control
1739 // otherwise setting DialogResult inside any of the events that are triggered by the
1740 // create will not actually cause the form to not be displayed.
1741 // Leaving this comment here in case there was an actual purpose to creating the control
1743 if (!IsHandleCreated) {
1748 Application.RunLoop(true, new ApplicationContext(this));
1750 if (owner != null) {
1751 // Cannot use Activate(), it has a check for the current active window...
1752 XplatUI.Activate(owner.window.Handle);
1755 if (IsHandleCreated) {
1759 if (DialogResult == DialogResult.None) {
1760 DialogResult = DialogResult.Cancel;
1763 return DialogResult;
1766 public override string ToString() {
1767 return GetType().FullName.ToString() + ", Text: " + Text;
1772 [EditorBrowsable (EditorBrowsableState.Always)]
1773 public override bool ValidateChildren ()
1775 return base.ValidateChildren ();
1779 [EditorBrowsable (EditorBrowsableState.Always)]
1780 public override bool ValidateChildren (ValidationConstraints validationConstraints)
1782 return base.ValidateChildren (validationConstraints);
1785 #endregion // Public Instance Methods
1787 #region Protected Instance Methods
1788 protected void ActivateMdiChild(Form form) {
1789 if (!IsMdiContainer)
1791 mdi_container.ActivateChild (form);
1792 OnMdiChildActivate(EventArgs.Empty);
1795 [EditorBrowsable(EditorBrowsableState.Advanced)]
1796 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1797 base.AdjustFormScrollbars (displayScrollbars);
1801 [EditorBrowsable(EditorBrowsableState.Never)]
1802 [Obsolete ("This method has been deprecated")] // XXX what to use instead?
1804 [EditorBrowsable(EditorBrowsableState.Advanced)]
1806 protected void ApplyAutoScaling()
1808 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1809 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1813 if (current_size == autoscale_base_size)
1816 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1821 // I tried applying the Fudge height factor from:
1822 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1823 // but it makes things larger without looking better.
1825 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1826 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1831 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1832 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1837 Scale (new SizeF (dx, dy));
1839 AutoScaleBaseSize = current_size;
1842 protected void CenterToParent() {
1847 // MS creates the handle here.
1849 if (!IsHandleCreated)
1856 w = DefaultSize.Width;
1862 h = DefaultSize.Height;
1866 if (Parent != null) {
1868 } else if (owner != null) {
1872 if (owner != null) {
1873 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1877 protected void CenterToScreen() {
1882 // MS creates the handle here.
1884 if (!IsHandleCreated)
1891 w = DefaultSize.Width;
1897 h = DefaultSize.Height;
1900 XplatUI.GetDisplaySize(out DisplaySize);
1901 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1904 [EditorBrowsable(EditorBrowsableState.Advanced)]
1905 protected override Control.ControlCollection CreateControlsInstance() {
1906 return base.CreateControlsInstance ();
1909 [EditorBrowsable(EditorBrowsableState.Advanced)]
1910 protected override void CreateHandle() {
1911 base.CreateHandle ();
1913 if (!IsHandleCreated) {
1919 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1920 if (allow_transparency) {
1921 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
1925 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1926 if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1927 XplatUI.SetIcon(window.Handle, icon);
1930 if ((owner != null) && (owner.IsHandleCreated)) {
1931 XplatUI.SetOwner(window.Handle, owner.window.Handle);
1935 XplatUI.SetTopmost(window.Handle, topmost);
1938 for (int i = 0; i < owned_forms.Count; i++) {
1939 if (owned_forms[i].IsHandleCreated)
1940 XplatUI.SetOwner(owned_forms[i].window.Handle, window.Handle);
1943 if (window_manager != null) {
1944 if (IsMdiChild && VisibleInternal) {
1945 MdiWindowManager wm;
1946 // Loop through all the other mdi siblings and raise Deactivate events.
1947 if (MdiParent != null) {
1948 foreach (Form form in MdiParent.MdiChildren) {
1949 wm = form.window_manager as MdiWindowManager;
1950 if (wm != null && form != this) {
1951 // This will only raise deactivate once, and only if activate has
1952 // already been raised.
1953 wm.RaiseDeactivate ();
1958 wm = window_manager as MdiWindowManager;
1959 wm.RaiseActivated ();
1962 if (window_state != FormWindowState.Normal) {
1963 window_manager.SetWindowState ((FormWindowState) int.MaxValue, window_state);
1965 XplatUI.RequestNCRecalc (window.Handle);
1970 [EditorBrowsable(EditorBrowsableState.Advanced)]
1971 protected override void DefWndProc(ref Message m) {
1972 base.DefWndProc (ref m);
1975 protected override void Dispose(bool disposing)
1977 for (int i = 0; i < owned_forms.Count; i++)
1978 ((Form)owned_forms[i]).Owner = null;
1980 owned_forms.Clear ();
1982 base.Dispose (disposing);
1984 Application.RemoveForm (this);
1987 [EditorBrowsable(EditorBrowsableState.Advanced)]
1988 protected virtual void OnActivated(EventArgs e)
1990 EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
1995 [EditorBrowsable(EditorBrowsableState.Advanced)]
1996 protected virtual void OnClosed(EventArgs e) {
1997 EventHandler eh = (EventHandler)(Events [ClosedEvent]);
2002 // Consider calling FireClosingEvents instead of calling this directly.
2003 [EditorBrowsable (EditorBrowsableState.Advanced)]
2004 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
2005 CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
2010 [EditorBrowsable(EditorBrowsableState.Advanced)]
2011 protected override void OnCreateControl() {
2012 base.OnCreateControl ();
2015 XplatUI.SetMenu(window.Handle, menu);
2018 OnLoadInternal (EventArgs.Empty);
2020 // Send initial location
2021 OnLocationChanged(EventArgs.Empty);
2024 [EditorBrowsable(EditorBrowsableState.Advanced)]
2025 protected virtual void OnDeactivate(EventArgs e) {
2026 EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
2031 [EditorBrowsable(EditorBrowsableState.Advanced)]
2032 protected override void OnFontChanged(EventArgs e) {
2033 base.OnFontChanged (e);
2036 [EditorBrowsable(EditorBrowsableState.Advanced)]
2037 protected override void OnHandleCreated(EventArgs e) {
2038 XplatUI.SetBorderStyle(window.Handle, form_border_style);
2039 base.OnHandleCreated (e);
2042 [EditorBrowsable(EditorBrowsableState.Advanced)]
2043 protected override void OnHandleDestroyed(EventArgs e) {
2044 Application.RemoveForm (this);
2045 base.OnHandleDestroyed (e);
2048 [EditorBrowsable(EditorBrowsableState.Advanced)]
2049 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
2050 InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
2055 [EditorBrowsable(EditorBrowsableState.Advanced)]
2056 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
2057 InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
2062 [EditorBrowsable(EditorBrowsableState.Advanced)]
2063 protected virtual void OnLoad (EventArgs e){
2064 Application.AddForm (this);
2066 EventHandler eh = (EventHandler)(Events[LoadEvent]);
2071 [EditorBrowsable(EditorBrowsableState.Advanced)]
2072 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
2073 EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
2078 [EditorBrowsable(EditorBrowsableState.Advanced)]
2079 protected virtual void OnMaximumSizeChanged(EventArgs e) {
2080 EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
2085 [EditorBrowsable(EditorBrowsableState.Advanced)]
2086 protected virtual void OnMdiChildActivate(EventArgs e) {
2087 EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
2092 [EditorBrowsable(EditorBrowsableState.Advanced)]
2093 protected virtual void OnMenuComplete(EventArgs e) {
2094 EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
2099 [EditorBrowsable(EditorBrowsableState.Advanced)]
2100 protected virtual void OnMenuStart(EventArgs e) {
2101 EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
2106 [EditorBrowsable(EditorBrowsableState.Advanced)]
2107 protected virtual void OnMinimumSizeChanged(EventArgs e) {
2108 EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
2113 [EditorBrowsable(EditorBrowsableState.Advanced)]
2114 protected override void OnPaint (PaintEventArgs pevent) {
2115 base.OnPaint (pevent);
2117 if (size_grip != null) {
2118 size_grip.HandlePaint (this, pevent);
2122 [EditorBrowsable(EditorBrowsableState.Advanced)]
2123 protected override void OnResize(EventArgs e) {
2128 [EditorBrowsable(EditorBrowsableState.Advanced)]
2129 protected override void OnStyleChanged(EventArgs e) {
2130 base.OnStyleChanged (e);
2133 [EditorBrowsable(EditorBrowsableState.Advanced)]
2134 protected override void OnTextChanged(EventArgs e) {
2135 base.OnTextChanged (e);
2137 if (mdi_container != null)
2138 mdi_container.SetParentText(true);
2141 [EditorBrowsable(EditorBrowsableState.Advanced)]
2142 protected override void OnVisibleChanged(EventArgs e) {
2143 base.OnVisibleChanged (e);
2146 if (window_manager != null)
2147 window_manager.SetWindowState (WindowState, WindowState);
2151 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
2152 if (base.ProcessCmdKey (ref msg, keyData)) {
2156 // Handle keyboard cues state.
2157 if ((keyData & Keys.Alt) != 0) {
2158 Control toplevel = TopLevelControl;
2159 if (toplevel != null) {
2160 IntPtr param = MakeParam ((int) MsgUIState.UIS_CLEAR, (int) MsgUIState.UISF_HIDEACCEL);
2161 XplatUI.SendMessage (toplevel.Handle, Msg.WM_CHANGEUISTATE, param, IntPtr.Zero);
2165 // Give our menu a shot
2166 if (ActiveMenu != null) {
2167 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
2173 case Keys.Control | Keys.F4:
2174 case Keys.Control | Keys.Shift | Keys.F4:
2177 case Keys.Control | Keys.Tab:
2178 case Keys.Control | Keys.F6:
2179 MdiParent.MdiContainer.ActivateNextChild ();
2181 case Keys.Control | Keys.Shift | Keys.Tab:
2182 case Keys.Control | Keys.Shift | Keys.F6:
2183 MdiParent.MdiContainer.ActivatePreviousChild ();
2191 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
2192 [EditorBrowsable (EditorBrowsableState.Advanced)]
2193 protected override bool ProcessDialogChar(char charCode) {
2194 return base.ProcessDialogChar (charCode);
2197 protected override bool ProcessDialogKey(Keys keyData) {
2198 if ((keyData & Keys.Modifiers) == 0) {
2199 if (keyData == Keys.Enter) {
2200 IntPtr window = XplatUI.GetFocus ();
2201 Control c = Control.FromHandle (window);
2202 if (c is Button && c.FindForm () == this) {
2203 ((Button)c).PerformClick ();
2206 else if (accept_button != null) {
2207 accept_button.PerformClick();
2210 } else if (keyData == Keys.Escape && cancel_button != null) {
2211 cancel_button.PerformClick();
2215 return base.ProcessDialogKey(keyData);
2218 protected override bool ProcessKeyPreview(ref Message msg) {
2220 if (ProcessKeyEventArgs(ref msg)) {
2224 return base.ProcessKeyPreview (ref msg);
2227 protected override bool ProcessTabKey(bool forward) {
2228 bool need_refresh = !show_focus_cues;
2229 show_focus_cues = true;
2231 bool control_activated = SelectNextControl(ActiveControl, forward, true, true, true);
2233 if (need_refresh && ActiveControl != null)
2234 ActiveControl.Invalidate ();
2236 return control_activated;
2240 [EditorBrowsable(EditorBrowsableState.Never)]
2242 [EditorBrowsable(EditorBrowsableState.Advanced)]
2244 protected override void ScaleCore(float dx, float dy) {
2248 // We can't scale max or min windows
2249 if (WindowState == FormWindowState.Normal) {
2250 // We cannot call base since base also adjusts X/Y, but
2251 // a form is toplevel and doesn't move
2255 if (!GetStyle(ControlStyles.FixedWidth)) {
2256 size.Width = (int)(size.Width * dx);
2259 if (!GetStyle(ControlStyles.FixedHeight)) {
2260 size.Height = (int)(size.Height * dy);
2266 /* Now scale our children */
2267 Control [] controls = Controls.GetAllControls ();
2268 for (int i=0; i < controls.Length; i++) {
2269 controls[i].Scale (new SizeF (dx, dy));
2278 protected override void Select(bool directed, bool forward) {
2282 // MS causes the handle to be created here.
2283 if (!IsHandleCreated)
2284 if (!IsHandleCreated)
2288 base.SelectNextControl(null, forward, true, true, true);
2291 parent = this.ParentForm;
2292 if (parent != null) {
2293 parent.ActiveControl = this;
2299 [EditorBrowsable(EditorBrowsableState.Advanced)]
2300 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2301 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width)
2302 width = Math.Max (width, SystemInformation.MinimumWindowSize.Width);
2303 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height)
2304 height = Math.Max (height, SystemInformation.MinimumWindowSize.Height);
2306 base.SetBoundsCore (x, y, width, height, specified);
2309 [EditorBrowsable(EditorBrowsableState.Advanced)]
2310 protected override void SetClientSizeCore(int x, int y) {
2311 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
2312 x = minimum_size.Width;
2313 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
2314 x = maximum_size.Width;
2317 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
2318 y = minimum_size.Height;
2319 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
2320 y = maximum_size.Height;
2323 Rectangle ClientRect = new Rectangle(0, 0, x, y);
2324 Rectangle WindowRect;
2325 CreateParams cp = this.CreateParams;
2327 clientsize_set = new Size(x, y);
2329 if (XplatUI.CalculateWindowRect(ref ClientRect, cp, cp.menu, out WindowRect)) {
2330 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2334 [EditorBrowsable(EditorBrowsableState.Advanced)]
2335 protected override void SetVisibleCore(bool value)
2337 if (IsMdiChild && !MdiParent.Visible) {
2338 if (value != Visible) {
2339 MdiWindowManager wm = (MdiWindowManager) window_manager;
2340 wm.IsVisiblePending = value;
2341 OnVisibleChanged (EventArgs.Empty);
2345 is_changing_visible_state++;
2346 has_been_visible = value || has_been_visible;
2347 base.SetVisibleCore (value);
2349 Application.AddForm (this);
2352 if (value && WindowState != FormWindowState.Normal)
2353 XplatUI.SendMessage (Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
2355 is_changing_visible_state--;
2358 if (value && IsMdiContainer) {
2359 Form [] children = MdiChildren;
2360 for (int i = 0; i < children.Length; i++) {
2361 Form child = children [i];
2362 MdiWindowManager wm = (MdiWindowManager) child.window_manager;
2363 if (!child.IsHandleCreated && wm.IsVisiblePending) {
2364 wm.IsVisiblePending = false;
2365 child.Visible = true;
2370 if (value && IsMdiChild){
2372 ThemeEngine.Current.ManagedWindowSetButtonLocations (window_manager);
2375 // Shown event is only called once, the first time the form is made visible
2376 if (value && !shown_raised) {
2378 this.OnShown (EventArgs.Empty);
2380 shown_raised = true;
2384 protected override void UpdateDefaultButton() {
2385 base.UpdateDefaultButton ();
2388 [EditorBrowsable(EditorBrowsableState.Advanced)]
2389 protected override void WndProc(ref Message m) {
2391 Console.WriteLine(DateTime.Now.ToLongTimeString () + " Form {0} ({2}) received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString (), Text);
2394 if (window_manager != null && window_manager.WndProc (ref m)) {
2398 switch ((Msg)m.Msg) {
2399 case Msg.WM_DESTROY: {
2404 case Msg.WM_CLOSE: {
2409 case Msg.WM_WINDOWPOSCHANGED: {
2410 WmWindowPosChanged (ref m);
2415 case Msg.WM_SYSCOMMAND: {
2416 WmSysCommand (ref m);
2421 case Msg.WM_ACTIVATE: {
2426 case Msg.WM_KILLFOCUS: {
2427 WmKillFocus (ref m);
2431 case Msg.WM_SETFOCUS: {
2437 case Msg.WM_NCHITTEST: {
2438 WmNcHitTest (ref m);
2442 case Msg.WM_NCLBUTTONDOWN: {
2443 WmNcLButtonDown (ref m);
2447 case Msg.WM_NCLBUTTONUP: {
2448 WmNcLButtonUp (ref m);
2452 case Msg.WM_NCMOUSELEAVE: {
2453 WmNcMouseLeave (ref m);
2457 case Msg.WM_NCMOUSEMOVE: {
2458 WmNcMouseMove (ref m);
2462 case Msg.WM_NCPAINT: {
2467 case Msg.WM_NCCALCSIZE: {
2468 WmNcCalcSize (ref m);
2472 case Msg.WM_MOUSEMOVE: {
2473 WmMouseMove (ref m);
2477 case Msg.WM_LBUTTONDOWN:
2478 case Msg.WM_MBUTTONDOWN:
2479 case Msg.WM_RBUTTONDOWN: {
2480 WmButtonDown (ref m);
2484 case Msg.WM_LBUTTONUP:
2485 case Msg.WM_MBUTTONUP:
2486 case Msg.WM_RBUTTONUP: {
2491 case Msg.WM_GETMINMAXINFO: {
2492 WmGetMinMaxInfo (ref m);
2497 base.WndProc (ref m);
2502 #endregion // Protected Instance Methods
2506 private void WmDestroy (ref Message m)
2508 if (!RecreatingHandle)
2509 this.closing = true;
2511 base.WndProc (ref m);
2514 internal bool RaiseCloseEvents (bool last_check)
2516 if (last_check && Visible) {
2520 if (last_check && closed) {
2524 bool cancelled = FireClosingEvents (CloseReason.UserClosing);
2526 if (!last_check || DialogResult != DialogResult.None) {
2527 OnClosed (EventArgs.Empty);
2529 OnFormClosed (new FormClosedEventArgs (CloseReason.UserClosing));
2534 DialogResult = DialogResult.None;
2541 private void WmClose (ref Message m)
2543 Form act = Form.ActiveForm;
2544 // Don't close this form if there's another modal form visible.
2545 if (act != null && act != this && act.Modal == true) {
2546 // Check if any of the parents up the tree is the modal form,
2547 // in which case we can still close this form.
2548 Control current = this;
2549 while (current != null && current.Parent != act) {
2550 current = current.Parent;
2552 if (current == null || current.Parent != act) {
2557 if (mdi_container != null) {
2558 foreach (Form mdi_child in mdi_container.MdiChildren) {
2559 mdi_child.FireClosingEvents (CloseReason.MdiFormClosing);
2563 if (suppress_closing_events || !RaiseCloseEvents (false)) {
2571 DialogResult = DialogResult.None;
2579 private void WmWindowPosChanged (ref Message m)
2581 base.WndProc (ref m);
2585 private void WmSysCommand (ref Message m)
2587 // Let *Strips know the app's title bar was clicked
2588 if (XplatUI.IsEnabled (Handle))
2589 ToolStripManager.FireAppClicked ();
2591 base.WndProc (ref m);
2594 private void WmActivate (ref Message m)
2596 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
2598 SelectActiveControl ();
2600 if (ActiveControl != null && !ActiveControl.Focused)
2601 SendControlFocus (ActiveControl);
2607 if (XplatUI.IsEnabled (Handle) && XplatUI.GetParent (m.LParam) != Handle)
2608 ToolStripManager.FireAppFocusChanged (this);
2614 private void WmKillFocus (ref Message m)
2616 base.WndProc (ref m);
2619 private void WmSetFocus (ref Message m)
2621 if (ActiveControl != null && ActiveControl != this) {
2622 ActiveControl.Focus ();
2623 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
2625 if (IsMdiContainer) {
2626 mdi_container.SendFocusToActiveChild ();
2629 base.WndProc (ref m);
2632 private void WmNcHitTest (ref Message m)
2634 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
2635 int x = LowOrder ((int)m.LParam.ToInt32 ());
2636 int y = HighOrder ((int)m.LParam.ToInt32 ());
2638 XplatUI.ScreenToMenu (ActiveMenu.Wnd.window.Handle, ref x, ref y);
2640 // If point is under menu return HTMENU, it prevents Win32 to return HTMOVE.
2641 if ((x > 0) && (y > 0) && (x < ActiveMenu.Rect.Width) && (y < ActiveMenu.Rect.Height)) {
2642 m.Result = new IntPtr ((int)HitTest.HTMENU);
2647 base.WndProc (ref m);
2650 private void WmNcLButtonDown (ref Message m)
2652 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
2653 ActiveMenu.OnMouseDown (this, new MouseEventArgs (FromParamToMouseButtons ((int)m.WParam.ToInt32 ()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
2656 if (ActiveMaximizedMdiChild != null && ActiveMenu != null) {
2657 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
2658 LowOrder ((int)m.LParam.ToInt32 ()),
2659 HighOrder ((int)m.LParam.ToInt32 ()))) {
2660 // Don't let base process this message, otherwise we won't
2661 // get a WM_NCLBUTTONUP.
2665 base.WndProc (ref m);
2668 private void WmNcLButtonUp (ref Message m)
2670 if (ActiveMaximizedMdiChild != null && ActiveMenu != null) {
2671 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
2672 LowOrder ((int)m.LParam.ToInt32 ()),
2673 HighOrder ((int)m.LParam.ToInt32 ()));
2675 base.WndProc (ref m);
2678 private void WmNcMouseLeave (ref Message m)
2680 if (ActiveMaximizedMdiChild != null && ActiveMenu != null) {
2681 ActiveMaximizedMdiChild.HandleMenuMouseLeave (ActiveMenu,
2682 LowOrder ((int)m.LParam.ToInt32 ()),
2683 HighOrder ((int)m.LParam.ToInt32 ()));
2685 base.WndProc (ref m);
2688 private void WmNcMouseMove (ref Message m)
2690 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
2691 ActiveMenu.OnMouseMove (this, new MouseEventArgs (FromParamToMouseButtons ((int)m.WParam.ToInt32 ()), mouse_clicks, LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()), 0));
2694 if (ActiveMaximizedMdiChild != null && ActiveMenu != null) {
2695 XplatUI.RequestAdditionalWM_NCMessages (Handle, false, true);
2696 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
2697 LowOrder ((int)m.LParam.ToInt32 ()),
2698 HighOrder ((int)m.LParam.ToInt32 ()));
2700 base.WndProc (ref m);
2703 private void WmNcPaint (ref Message m)
2705 if (ActiveMenu != null) {
2709 pe = XplatUI.PaintEventStart (ref m, Handle, false);
2710 pnt = XplatUI.GetMenuOrigin (window.Handle);
2712 // The entire menu has to be in the clip rectangle because the
2713 // control buttons are right-aligned and otherwise they would
2714 // stay painted when the window gets resized.
2715 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
2716 clip = Rectangle.Union (clip, pe.ClipRectangle);
2718 pe.Graphics.SetClip (clip);
2720 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
2722 if (ActiveMaximizedMdiChild != null) {
2723 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
2726 XplatUI.PaintEventEnd (ref m, Handle, false);
2729 base.WndProc (ref m);
2732 private void WmNcCalcSize (ref Message m)
2734 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
2736 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
2737 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure (m.LParam, typeof (XplatUIWin32.NCCALCSIZE_PARAMS));
2740 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ClientSize.Width);
2741 Marshal.StructureToPtr (ncp, m.LParam, true);
2746 private void WmMouseMove (ref Message m)
2748 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2749 MouseEventArgs args = new MouseEventArgs (
2750 FromParamToMouseButtons ((int)m.WParam.ToInt32 ()),
2752 Control.MousePosition.X,
2753 Control.MousePosition.Y,
2756 active_tracker.OnMotion (args);
2759 base.WndProc (ref m);
2762 private void WmButtonDown (ref Message m)
2764 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2765 MouseEventArgs args = new MouseEventArgs (
2766 FromParamToMouseButtons ((int)m.WParam.ToInt32 ()),
2768 Control.MousePosition.X,
2769 Control.MousePosition.Y,
2772 if (!active_tracker.OnMouseDown (args)) {
2773 Control control = GetRealChildAtPoint (Cursor.Position);
2774 if (control != null) {
2775 Point pt = control.PointToClient (Cursor.Position);
2776 XplatUI.SendMessage (control.Handle, (Msg)m.Msg, m.WParam, MakeParam (pt.X, pt.Y));
2783 base.WndProc (ref m);
2786 private void WmButtonUp (ref Message m)
2788 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2789 MouseButtons mb = FromParamToMouseButtons ((int)m.WParam.ToInt32 ());
2791 // We add in the button that was released (not sent in WParam)
2792 switch ((Msg)m.Msg) {
2793 case Msg.WM_LBUTTONUP:
2794 mb |= MouseButtons.Left;
2796 case Msg.WM_MBUTTONUP:
2797 mb |= MouseButtons.Middle;
2799 case Msg.WM_RBUTTONUP:
2800 mb |= MouseButtons.Right;
2804 MouseEventArgs args = new MouseEventArgs (
2807 Control.MousePosition.X,
2808 Control.MousePosition.Y,
2811 active_tracker.OnMouseUp (args);
2815 base.WndProc (ref m);
2818 private void WmGetMinMaxInfo (ref Message m)
2822 if (m.LParam != IntPtr.Zero) {
2823 mmi = (MINMAXINFO)Marshal.PtrToStructure (m.LParam, typeof (MINMAXINFO));
2825 default_maximized_bounds = new Rectangle (mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2826 if (maximized_bounds != Rectangle.Empty) {
2827 mmi.ptMaxPosition.x = maximized_bounds.Left;
2828 mmi.ptMaxPosition.y = maximized_bounds.Top;
2829 mmi.ptMaxSize.x = maximized_bounds.Width;
2830 mmi.ptMaxSize.y = maximized_bounds.Height;
2833 if (minimum_size != Size.Empty) {
2834 mmi.ptMinTrackSize.x = minimum_size.Width;
2835 mmi.ptMinTrackSize.y = minimum_size.Height;
2838 if (maximum_size != Size.Empty) {
2839 mmi.ptMaxTrackSize.x = maximum_size.Width;
2840 mmi.ptMaxTrackSize.y = maximum_size.Height;
2842 Marshal.StructureToPtr (mmi, m.LParam, false);
2847 #region Internal / Private Methods
2848 internal override void FireEnter ()
2850 // do nothing - forms don't generate OnEnter
2853 internal override void FireLeave ()
2855 // do nothing - forms don't generate OnLeave
2858 internal void RemoveWindowManager ()
2860 window_manager = null;
2863 internal override void CheckAcceptButton ()
2865 if (accept_button != null) {
2866 Button a_button = accept_button as Button;
2868 if (ActiveControl == a_button)
2871 // If the accept_button isn't a Button, we don't need to do
2872 // the rest of this.
2873 if (a_button == null)
2876 if (ActiveControl is Button)
2877 a_button.paint_as_acceptbutton = false;
2879 a_button.paint_as_acceptbutton = true;
2881 a_button.Invalidate ();
2885 internal override bool ActivateOnShow { get { return !this.ShowWithoutActivation; } }
2887 private void OnLoadInternal (EventArgs e)
2890 ApplyAutoScaling ();
2901 if (!IsMdiChild && !IsDisposed) {
2902 switch (StartPosition) {
2903 case FormStartPosition.CenterScreen:
2904 this.CenterToScreen ();
2906 case FormStartPosition.CenterParent:
2907 this.CenterToParent ();
2909 case FormStartPosition.Manual:
2910 Left = CreateParams.X;
2911 Top = CreateParams.Y;
2921 static object ActivatedEvent = new object ();
2922 static object ClosedEvent = new object ();
2923 static object ClosingEvent = new object ();
2924 static object DeactivateEvent = new object ();
2925 static object InputLanguageChangedEvent = new object ();
2926 static object InputLanguageChangingEvent = new object ();
2927 static object LoadEvent = new object ();
2928 static object MaximizedBoundsChangedEvent = new object ();
2929 static object MaximumSizeChangedEvent = new object ();
2930 static object MdiChildActivateEvent = new object ();
2931 static object MenuCompleteEvent = new object ();
2932 static object MenuStartEvent = new object ();
2933 static object MinimumSizeChangedEvent = new object ();
2935 public event EventHandler Activated {
2936 add { Events.AddHandler (ActivatedEvent, value); }
2937 remove { Events.RemoveHandler (ActivatedEvent, value); }
2942 [EditorBrowsable (EditorBrowsableState.Never)]
2944 public event EventHandler Closed {
2945 add { Events.AddHandler (ClosedEvent, value); }
2946 remove { Events.RemoveHandler (ClosedEvent, value); }
2951 [EditorBrowsable (EditorBrowsableState.Never)]
2953 public event CancelEventHandler Closing {
2954 add { Events.AddHandler (ClosingEvent, value); }
2955 remove { Events.RemoveHandler (ClosingEvent, value); }
2958 public event EventHandler Deactivate {
2959 add { Events.AddHandler (DeactivateEvent, value); }
2960 remove { Events.RemoveHandler (DeactivateEvent, value); }
2963 public event InputLanguageChangedEventHandler InputLanguageChanged {
2964 add { Events.AddHandler (InputLanguageChangedEvent, value); }
2965 remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
2968 public event InputLanguageChangingEventHandler InputLanguageChanging {
2969 add { Events.AddHandler (InputLanguageChangingEvent, value); }
2970 remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
2973 public event EventHandler Load {
2974 add { Events.AddHandler (LoadEvent, value); }
2975 remove { Events.RemoveHandler (LoadEvent, value); }
2978 public event EventHandler MaximizedBoundsChanged {
2979 add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
2980 remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
2983 public event EventHandler MaximumSizeChanged {
2984 add { Events.AddHandler (MaximumSizeChangedEvent, value); }
2985 remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
2988 public event EventHandler MdiChildActivate {
2989 add { Events.AddHandler (MdiChildActivateEvent, value); }
2990 remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
2996 public event EventHandler MenuComplete {
2997 add { Events.AddHandler (MenuCompleteEvent, value); }
2998 remove { Events.RemoveHandler (MenuCompleteEvent, value); }
3004 public event EventHandler MenuStart {
3005 add { Events.AddHandler (MenuStartEvent, value); }
3006 remove { Events.RemoveHandler (MenuStartEvent, value); }
3009 public event EventHandler MinimumSizeChanged {
3010 add { Events.AddHandler (MinimumSizeChangedEvent, value); }
3011 remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
3016 [EditorBrowsable(EditorBrowsableState.Never)]
3017 public new event EventHandler TabIndexChanged {
3018 add { base.TabIndexChanged += value; }
3019 remove { base.TabIndexChanged -= value; }
3023 [SettingsBindable (true)]
3024 public override string Text {
3034 [SettingsBindable (true)]
3035 public new Point Location {
3037 return base.Location;
3041 base.Location = value;
3045 static object FormClosingEvent = new object ();
3046 static object FormClosedEvent = new object ();
3047 static object HelpButtonClickedEvent = new object ();
3048 static object ResizeEndEvent = new object ();
3049 static object ResizeBeginEvent = new object ();
3050 static object RightToLeftLayoutChangedEvent = new object ();
3051 static object ShownEvent = new object ();
3054 [EditorBrowsable (EditorBrowsableState.Always)]
3055 public new event EventHandler AutoSizeChanged {
3056 add { base.AutoSizeChanged += value; }
3057 remove { base.AutoSizeChanged -= value; }
3061 [EditorBrowsable (EditorBrowsableState.Always)]
3062 public new event EventHandler AutoValidateChanged {
3063 add { base.AutoValidateChanged += value; }
3064 remove { base.AutoValidateChanged -= value; }
3067 public event FormClosingEventHandler FormClosing {
3068 add { Events.AddHandler (FormClosingEvent, value); }
3069 remove { Events.RemoveHandler (FormClosingEvent, value); }
3072 public event FormClosedEventHandler FormClosed {
3073 add { Events.AddHandler (FormClosedEvent, value); }
3074 remove { Events.RemoveHandler (FormClosedEvent, value); }
3078 [EditorBrowsable (EditorBrowsableState.Always)]
3079 public event CancelEventHandler HelpButtonClicked {
3080 add { Events.AddHandler (HelpButtonClickedEvent, value); }
3081 remove { Events.RemoveHandler (HelpButtonClickedEvent, value); }
3085 [EditorBrowsable (EditorBrowsableState.Never)]
3086 public new event EventHandler MarginChanged {
3087 add { base.MarginChanged += value; }
3088 remove { base.MarginChanged -= value; }
3091 public event EventHandler RightToLeftLayoutChanged {
3092 add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
3093 remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
3096 public event EventHandler ResizeBegin {
3097 add { Events.AddHandler (ResizeBeginEvent, value); }
3098 remove { Events.RemoveHandler (ResizeBeginEvent, value); }
3101 public event EventHandler ResizeEnd {
3102 add { Events.AddHandler (ResizeEndEvent, value); }
3103 remove { Events.RemoveHandler (ResizeEndEvent, value); }
3106 public event EventHandler Shown {
3107 add { Events.AddHandler (ShownEvent, value); }
3108 remove { Events.RemoveHandler (ShownEvent, value); }
3112 [EditorBrowsable (EditorBrowsableState.Never)]
3113 public new event EventHandler TabStopChanged {
3114 add { base.TabStopChanged += value; }
3115 remove { base.TabStopChanged -= value; }
3118 protected override void OnBackgroundImageChanged (EventArgs e)
3120 base.OnBackgroundImageChanged (e);
3123 protected override void OnBackgroundImageLayoutChanged (EventArgs e)
3125 base.OnBackgroundImageLayoutChanged (e);
3128 [EditorBrowsable (EditorBrowsableState.Advanced)]
3129 protected override void OnEnabledChanged (EventArgs e)
3131 base.OnEnabledChanged (e);
3134 [EditorBrowsable (EditorBrowsableState.Advanced)]
3135 protected override void OnEnter (EventArgs e)
3140 [EditorBrowsable (EditorBrowsableState.Advanced)]
3141 protected virtual void OnFormClosed (FormClosedEventArgs e) {
3142 Application.RemoveForm (this);
3143 FormClosedEventHandler eh = (FormClosedEventHandler)(Events[FormClosedEvent]);
3148 // Consider calling FireClosingEvents instead of calling this directly.
3149 [EditorBrowsable (EditorBrowsableState.Advanced)]
3150 protected virtual void OnFormClosing (FormClosingEventArgs e)
3152 FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);
3157 [MonoTODO ("Not hooked up to event")]
3158 [EditorBrowsable (EditorBrowsableState.Advanced)]
3159 protected virtual void OnHelpButtonClicked (CancelEventArgs e)
3161 CancelEventHandler eh = (CancelEventHandler)(Events[HelpButtonClickedEvent]);
3166 protected override void OnLayout (LayoutEventArgs levent)
3168 base.OnLayout (levent);
3171 Size new_size = GetPreferredSizeCore (Size.Empty);
3172 if (AutoSizeMode == AutoSizeMode.GrowOnly) {
3173 new_size.Width = Math.Max (new_size.Width, Width);
3174 new_size.Height = Math.Max (new_size.Height, Height);
3176 if (new_size == Size)
3178 SetBounds (bounds.X, bounds.Y, new_size.Width, new_size.Height, BoundsSpecified.None);
3182 [EditorBrowsable (EditorBrowsableState.Advanced)]
3183 protected virtual void OnResizeBegin (EventArgs e)
3185 EventHandler eh = (EventHandler) (Events [ResizeBeginEvent]);
3190 [EditorBrowsable (EditorBrowsableState.Advanced)]
3191 protected virtual void OnResizeEnd (EventArgs e)
3193 EventHandler eh = (EventHandler) (Events [ResizeEndEvent]);
3198 [EditorBrowsable (EditorBrowsableState.Advanced)]
3199 protected virtual void OnRightToLeftLayoutChanged (EventArgs e)
3201 EventHandler eh = (EventHandler)(Events[RightToLeftLayoutChangedEvent]);
3206 [EditorBrowsable (EditorBrowsableState.Advanced)]
3207 protected virtual void OnShown (EventArgs e)
3209 EventHandler eh = (EventHandler) (Events [ShownEvent]);
3214 #endregion // Events