2007-02-23 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
index b99e06e2cdb3baa76510af31b1844234e3a7b54f..724b3b2d344c7c8b31e77329621bba8690eeea9c 100644 (file)
@@ -39,6 +39,11 @@ namespace System.Windows.Forms {
        [DesignTimeVisible(false)]
        [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
        [DefaultEvent("Load")]
+#if NET_2_0
+       [ClassInterface (ClassInterfaceType.AutoDispatch)]
+       [InitializationEvent ("Load")]
+       [ComVisible (true)]
+#endif
        [ToolboxItem(false)]
        public class Form : ContainerControl {
                #region Local Variables
@@ -72,6 +77,7 @@ namespace System.Windows.Forms {
                private Size                    maximum_size;
                private Size                    minimum_size;
                private SizeGripStyle           size_grip_style;
+               private SizeGrip                size_grip;
                private Rectangle               maximized_bounds;
                private Rectangle               default_maximized_bounds;
                private double                  opacity;
@@ -79,7 +85,14 @@ namespace System.Windows.Forms {
                Color                           transparency_key;
                internal MenuTracker            active_tracker;
                private bool                    is_loaded;
+               internal bool                   is_changing_visible_state;
+               internal bool                   has_been_visible;
 
+#if NET_2_0
+               private MenuStrip               main_menu_strip;
+               private bool                    show_icon = true;
+               private bool                    shown_raised;  // The shown event is only raised once
+#endif
                #endregion      // Local Variables
 
                #region Private & Internal Methods
@@ -96,10 +109,29 @@ namespace System.Windows.Forms {
                        }
                }
 
+               // Convenience method for fire BOTH OnClosing and OnFormClosing events
+               // Returns the value of Cancel, so true means the Close was cancelled,
+               // and you shouldn't close the form.
+               internal bool FireClosingEvents (CloseReason reason)
+               {
+                       CancelEventArgs cea = new CancelEventArgs ();
+                       this.OnClosing (cea);
+                       
+#if NET_2_0
+                       FormClosingEventArgs fcea = new FormClosingEventArgs (reason, cea.Cancel);
+                       this.OnFormClosing (fcea);
+                       return fcea.Cancel;
+#else
+                       return cea.Cancel;
+#endif
+               }
+               
                private void SelectActiveControl ()
                {
-                       if (this.IsMdiContainer)
+                       if (this.IsMdiContainer) {
+                               mdi_container.SendFocusToActiveChild ();
                                return;
+                       }
                                
                        if (this.ActiveControl == null) {
                                bool visible;
@@ -118,9 +150,47 @@ namespace System.Windows.Forms {
                                Select (ActiveControl);
                        }
                }
+               
+               private new void UpdateSizeGripVisible ()
+               {
+                       // Following link explains when to show size grip:
+                       // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=138687&SiteID=1
+                       // if SizeGripStyle.Auto, only shown if form is shown using ShowDialog and is sizable
+                       // if SizeGripStyle.Show, only shown if form is sizable
+                       
+                       bool show = false;
+                       
+                       switch (size_grip_style) {
+                       case SizeGripStyle.Auto:
+                               show = is_modal && (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
+                               break;
+                       case SizeGripStyle.Hide:
+                               show = false;
+                               break;
+                       case SizeGripStyle.Show:
+                               show = (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
+                               break;
+                       }
+                       
+                       if (!show) {
+                               if (size_grip != null && size_grip.Visible)
+                                       size_grip.Visible = false;
+                       } else {
+                               if (size_grip == null) {
+                                       size_grip = new SizeGrip (this);
+                                       size_grip.Virtual = true;
+                                       size_grip.FillBackground = false;
+                               }
+                               size_grip.Visible = true;
+                       }
+               }
+               
                #endregion      // Private & Internal Methods
 
                #region Public Classes
+#if NET_2_0
+               [ComVisible (false)]
+#endif         
                public new class ControlCollection : Control.ControlCollection {
                        Form    form_owner;
 
@@ -132,7 +202,7 @@ namespace System.Windows.Forms {
                                if (Contains (value))
                                        return;
                                AddToList (value);
-                               ((Form)value).owner=(Form)owner;
+                               ((Form)value).owner=form_owner;
                        }
 
                        public override void Remove(Control value) {
@@ -168,7 +238,6 @@ namespace System.Windows.Forms {
                        maximize_box = true;
                        help_button = false;
                        show_in_taskbar = true;
-                       ime_mode = ImeMode.NoControl;
                        is_visible = false;
                        is_toplevel = true;
                        size_grip_style = SizeGripStyle.Auto;
@@ -237,11 +306,11 @@ namespace System.Windows.Forms {
                                        return;
                                }
 
-                               if (XplatUI.SupportsTransparency()) {
-                                       allow_transparency = value;
+                               allow_transparency = value;
 
-                                       if (value) {
-                                               if (IsHandleCreated) {
+                               if (value) {
+                                       if (IsHandleCreated) {
+                                               if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
                                                        XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
                                                }
                                        } else {
@@ -251,7 +320,14 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               [Obsolete ("This property has been deprecated in favor of AutoScaleMode.")]
+#else
                [DefaultValue(true)]
+#endif
                [MWFCategory("Layout")]
                public bool AutoScale {
                        get {
@@ -263,9 +339,14 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
+#else
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+#endif
                [Localizable(true)]
                [Browsable(false)]
-               [EditorBrowsable(EditorBrowsableState.Advanced)]
                public virtual Size AutoScaleBaseSize {
                        get {
                                return autoscale_base_size;
@@ -310,19 +391,17 @@ namespace System.Windows.Forms {
 
                        set {
                                cancel_button = value;
+                               if (cancel_button != null && cancel_button.DialogResult == DialogResult.None)
+                                       cancel_button.DialogResult = DialogResult.Cancel;
                        }
                }
 
+               // new property so we can change the DesignerSerializationVisibility
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
                [Localizable(true)]
-               public Size ClientSize {
-                       get {
-                               return base.ClientSize;
-                       }
-
-                       set {
-                               base.ClientSize = value;
-                       }
+               public new Size ClientSize {
+                       get { return base.ClientSize; }
+                       set { base.ClientSize = value; }
                }
 
                [DefaultValue(true)]
@@ -400,6 +479,11 @@ namespace System.Windows.Forms {
                                }
 
                                UpdateStyles();
+                               
+                               if (this.Visible) 
+                                       this.Size = SizeFromClientSize (this.ClientSize);
+                               else
+                                       XplatUI.InvalidateNC (this.Handle);
                        }
                }
 
@@ -458,6 +542,7 @@ namespace System.Windows.Forms {
                                        Controls.Add(mdi_container);
                                        ControlAdded += new ControlEventHandler (ControlAddedHandler);
                                        mdi_container.SendToBack ();
+                                       mdi_container.SetParentText (true);
                                } else if (!value && mdi_container != null) {
                                        Controls.Remove(mdi_container);
                                        mdi_container = null;
@@ -494,6 +579,27 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [DefaultValue (null)]
+               [TypeConverter (typeof (ReferenceConverter))]
+               public MenuStrip MainMenuStrip {
+                       get { return this.main_menu_strip; }
+                       set { 
+                               if (this.main_menu_strip != value) {
+                                       this.main_menu_strip = value;
+                                       this.main_menu_strip.RefreshMdiItems ();
+                               }
+                       }
+               }
+               
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               [Browsable (false)]
+               public new Padding Margin {
+                       get { return base.Margin; }
+                       set { base.Margin = value; }
+               }
+#endif
+
                [DefaultValue(true)]
                [MWFCategory("Window Style")]
                public bool MaximizeBox {
@@ -515,7 +621,11 @@ namespace System.Windows.Forms {
                [Localizable(true)]
                [RefreshProperties(RefreshProperties.Repaint)]
                [MWFCategory("Layout")]
-               public Size MaximumSize {
+               public
+#if NET_2_0
+               override
+#endif
+               Size MaximumSize {
                        get {
                                return maximum_size;
                        }
@@ -551,10 +661,10 @@ namespace System.Windows.Forms {
 
                        set {
                                if (value != null && !value.IsMdiContainer)
-                                       throw new ArgumentException ();
+                                       throw new ArgumentException ("Form that was specified to be "
+                                               + "the MdiParent for this form is not an MdiContainer.");
 
                                if (mdi_parent != null) {
-                                       mdi_parent.MdiContainer.original_order.Remove (this);
                                        mdi_parent.MdiContainer.Controls.Remove (this);
                                }
 
@@ -562,8 +672,8 @@ namespace System.Windows.Forms {
                                        mdi_parent = value;
                                        window_manager = new MdiWindowManager (this,
                                                        mdi_parent.MdiContainer);
-                                       mdi_parent.MdiContainer.original_order.Add (this);
                                        mdi_parent.MdiContainer.Controls.Add (this);
+                                       mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
 
                                        RecreateHandle ();
 
@@ -598,6 +708,10 @@ namespace System.Windows.Forms {
                        get { return window_manager; }
                }
 
+#if NET_2_0
+               [Browsable (false)]
+               [TypeConverter (typeof (ReferenceConverter))]
+#endif
                [DefaultValue(null)]
                [MWFCategory("Window Style")]
                public MainMenu Menu {
@@ -687,11 +801,17 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if !NET_2_0
                [DefaultValue("{Width=0, Height=0}")]
+#endif
                [Localizable(true)]
                [RefreshProperties(RefreshProperties.Repaint)]
                [MWFCategory("Layout")]
-               public Size MinimumSize {
+               public
+#if NET_2_0
+               override
+#endif
+               Size MinimumSize {
                        get {
                                return minimum_size;
                        }
@@ -726,6 +846,11 @@ namespace System.Windows.Forms {
                [MWFCategory("Window Style")]
                public double Opacity {
                        get {
+                               if (IsHandleCreated) {
+                                       if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
+                                               return XplatUI.GetWindowTransparency (Handle);
+                               }
+
                                return opacity;
                        }
 
@@ -736,7 +861,8 @@ namespace System.Windows.Forms {
 
                                if (IsHandleCreated) {
                                        UpdateStyles();
-                                       XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
+                                       if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
+                                               XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
                                }
                        }
                }
@@ -784,6 +910,22 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [DefaultValue (true)]
+               public bool ShowIcon {
+                       get { return this.show_icon; }
+                       set {
+                               if (this.show_icon != value ) {
+                                       this.show_icon = value;
+                                       UpdateStyles ();
+                                       
+                                       XplatUI.SetIcon (this.Handle, value == true ? this.Icon : null);
+                                       XplatUI.InvalidateNC (this.Handle);
+                               }
+                       }
+               }                       
+#endif
+       
                [DefaultValue(true)]
                [MWFCategory("Window Style")]
                public bool ShowInTaskbar {
@@ -801,19 +943,14 @@ namespace System.Windows.Forms {
                        }
                }
 
+               // new property so we can set the DesignerSerializationVisibility
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [Localizable(false)]
-               public Size Size {
-                       get {
-                               return base.Size;
-                       }
-
-                       set {
-                               base.Size = value;
-                       }
+               public new Size Size {
+                       get { return base.Size; }
+                       set { base.Size = value; }
                }
 
-               [MonoTODO("Trigger something when GripStyle is set")]
                [DefaultValue(SizeGripStyle.Auto)]
                [MWFCategory("Window Style")]
                public SizeGripStyle SizeGripStyle {
@@ -823,6 +960,7 @@ namespace System.Windows.Forms {
 
                        set {
                                size_grip_style = value;
+                               UpdateSizeGripVisible ();
                        }
                }
 
@@ -864,18 +1002,25 @@ namespace System.Windows.Forms {
                        }
                }
 
+               // new property so we can set EditorBrowsable to never
                [Browsable(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [EditorBrowsable(EditorBrowsableState.Never)]
-               public int TabIndex {
-                       get {
-                               return base.TabIndex;
-                       }
+               public new int TabIndex {
+                       get { return base.TabIndex; }
+                       set { base.TabIndex = value; }
+               }
 
-                       set {
-                               base.TabIndex = value;
-                       }
+#if NET_2_0
+               [Browsable(false)]
+               [DefaultValue (true)]
+               [DispIdAttribute (-516)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
+               public new bool TabStop {
+                       get { return base.TabStop; }
+                       set { base.TabStop = value; }
                }
+#endif
 
                [Browsable(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
@@ -919,7 +1064,8 @@ namespace System.Windows.Forms {
 
                                AllowTransparency = true;
                                UpdateStyles();
-                               XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
+                               if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
+                                       XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
                        }
                }
 
@@ -983,6 +1129,11 @@ namespace System.Windows.Forms {
 
                                cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
 
+                               if (Parent != null) {
+                                       cp.Parent = Parent.Handle;
+                                       cp.Style |= (int) WindowStyles.WS_CHILD;
+                               }
+
                                if (IsMdiChild) {
                                        cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
                                        if (Parent != null) {
@@ -1077,6 +1228,12 @@ namespace System.Windows.Forms {
                                        cp.Style |= (int)WindowStyles.WS_SYSMENU;
                                }
 
+#if NET_2_0
+                               if (!this.show_icon) {
+                                       cp.ExStyle |= (int)WindowExStyles.WS_EX_DLGMODALFRAME;
+                               }
+#endif
+
                                if (HelpButton && !MaximizeBox && !MinimizeBox) {
                                        cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
                                }
@@ -1084,7 +1241,7 @@ namespace System.Windows.Forms {
                                if (Visible)
                                        cp.Style |= (int)WindowStyles.WS_VISIBLE;
 
-                               if (Opacity < 1.0 || TransparencyKey != Color.Empty) {
+                               if (opacity < 1.0 || TransparencyKey != Color.Empty) {
                                        cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
                                }
 
@@ -1124,10 +1281,21 @@ namespace System.Windows.Forms {
                                }
                        }
                }
+#if NET_2_0
+               [MonoTODO ("Implemented for Win32, needs X11 implementation")]
+               protected virtual bool ShowWithoutActivation {
+                       get { return false; }
+               }
+#endif
                #endregion      // Protected Instance Properties
 
                #region Public Static Methods
+#if NET_2_0
+               [EditorBrowsable(EditorBrowsableState.Never)]
+               [Obsolete ("This method has been deprecated.  Use AutoScaleDimensions instead")]
+#else
                [EditorBrowsable(EditorBrowsableState.Advanced)]
+#endif
                public static SizeF GetAutoScaleSize (Font font)
                {
                        return XplatUI.GetAutoScaleSize(font);
@@ -1154,13 +1322,16 @@ namespace System.Windows.Forms {
                        return new SizeF (width, font.Height);
                }
                                                 
-               public void Activate() {
+               public void Activate ()
+               {
                        Form    active;
 
                        // The docs say activate only activates if our app is already active
                        if (IsHandleCreated) {
                                if (IsMdiChild) {
                                        MdiParent.ActivateMdiChild (this);
+                               } else if (IsMdiContainer) {
+                                       mdi_container.SendFocusToActiveChild ();
                                } else {
                                        active = ActiveForm;
                                        if ((active != null) && (this != active)) {
@@ -1184,12 +1355,6 @@ namespace System.Windows.Forms {
                        if (!is_visible)
                                return;
 
-#if NET_2_0
-                       FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
-                       OnFormClosing (ce);
-                       if (ce.Cancel)
-                               return;
-#endif
                        XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                }
 
@@ -1211,6 +1376,21 @@ namespace System.Windows.Forms {
                        DesktopLocation = new Point(x, y);
                }
 
+#if NET_2_0
+               public void Show (IWin32Window owner)
+               {
+                       if (owner == null)
+                               this.Owner = null;
+                       else
+                               this.Owner = Control.FromHandle (owner.Handle).TopLevelControl as Form;
+
+                       if (owner == this)
+                               throw new InvalidOperationException ("The 'owner' cannot be the form being shown.");
+
+                       base.Show ();
+               }
+#endif
+
                public DialogResult ShowDialog() {
                        return ShowDialog(this.owner);
                }
@@ -1229,23 +1409,30 @@ namespace System.Windows.Forms {
                        }
 
                        if (owner == this) {
-                               throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
+                               throw new ArgumentException ("Forms cannot own themselves or their owners.", "owner");
                        }
 
                        if (is_modal) {
-                               throw new InvalidOperationException("The form is already displayed as a modal dialog.");
+                               throw new InvalidOperationException ("The form is already displayed as a modal dialog.");
                        }
 
                        if (Visible) {
-                               throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
+                               throw new InvalidOperationException ("Forms that are already "
+                                       + " visible cannot be displayed as a modal dialog. Set the"
+                                       + " form's visible property to false before calling"
+                                       + " ShowDialog.");
                        }
 
                        if (!Enabled) {
-                               throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
+                               throw new InvalidOperationException ("Forms that are not enabled"
+                                       + " cannot be displayed as a modal dialog. Set the form's"
+                                       + " enabled property to true before calling ShowDialog.");
                        }
 
                        if (TopLevelControl != this) {
-                               throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
+                               throw new InvalidOperationException ("Forms that are not top level"
+                                       + " forms cannot be displayed as a modal dialog. Remove the"
+                                       + " form from any parent form before calling ShowDialog.");
                        }
 
                        #if broken
@@ -1302,7 +1489,12 @@ namespace System.Windows.Forms {
                        base.AdjustFormScrollbars (displayScrollbars);
                }
 
+#if NET_2_0
+               [EditorBrowsable(EditorBrowsableState.Never)]
+               [Obsolete ("This method has been deprecated")] // XXX what to use instead?
+#else
                [EditorBrowsable(EditorBrowsableState.Advanced)]
+#endif
                protected void ApplyAutoScaling()
                {
                        SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
@@ -1357,8 +1549,8 @@ namespace System.Windows.Forms {
                        }
 
                        ctl = null;
-                       if (parent != null) {
-                               ctl = parent;
+                       if (Parent != null) {
+                               ctl = Parent;
                        } else if (owner != null) {
                                ctl = owner;
                        }
@@ -1398,14 +1590,19 @@ namespace System.Windows.Forms {
                protected override void CreateHandle() {
                        base.CreateHandle ();
 
+                       Application.AddForm (this);
+                       
                        UpdateBounds();
 
-                       if (XplatUI.SupportsTransparency()) {
+                       if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
                                if (allow_transparency) {
                                        XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
                                }
                        }
 
+                       if (this.ShowWithoutActivation)
+                               Hwnd.ObjectFromHandle (this.Handle).no_activate = true;
+
                        XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
                        if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
                                XplatUI.SetIcon(window.Handle, icon);
@@ -1420,8 +1617,11 @@ namespace System.Windows.Forms {
                                        XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
                        }
                        
-                       if (window_manager != null && window_state != FormWindowState.Normal) {
-                               window_manager.SetWindowState (FormWindowState.Normal, window_state);
+                       if (window_manager != null) {
+                               if (window_state != FormWindowState.Normal) {
+                                       window_manager.SetWindowState (FormWindowState.Normal, window_state);
+                               }
+                               XplatUI.RequestNCRecalc (window.Handle);
                        }
 
                }
@@ -1439,31 +1639,31 @@ namespace System.Windows.Forms {
                        owned_forms.Clear ();
                        
                        base.Dispose (disposing);
+                       
+                       Application.RemoveForm (this);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnActivated(EventArgs e)
                {
-                       if (is_loaded)
-                               SelectActiveControl ();
-
-                       if (Activated != null) {
-                               Activated(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnClosed(EventArgs e) {
-                       if (Closed != null) {
-                               Closed(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [ClosedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
-               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               // Consider calling FireClosingEvents instead of calling this directly.
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
-                       if (Closing != null) {
-                               Closing(this, e);
-                       }
+                       CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -1476,8 +1676,6 @@ namespace System.Windows.Forms {
 
                        OnLoad(EventArgs.Empty);
                        
-                       SelectActiveControl ();
-
                        // Send initial location
                        OnLocationChanged(EventArgs.Empty);
 
@@ -1488,9 +1686,9 @@ namespace System.Windows.Forms {
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnDeactivate(EventArgs e) {
-                       if (Deactivate != null) {
-                               Deactivate(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -1511,16 +1709,16 @@ namespace System.Windows.Forms {
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
-                       if (InputLanguageChanged!=null) {
-                               InputLanguageChanged(this, e);
-                       }
+                       InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
-                       if (InputLanguageChanging!=null) {
-                               InputLanguageChanging(this, e);
-                       }
+                       InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -1530,9 +1728,9 @@ namespace System.Windows.Forms {
                                AutoScale = false;
                        }
 
-                       if (Load != null) {
-                               Load(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [LoadEvent]);
+                       if (eh != null)
+                               eh (this, e);
 
                        if (!IsMdiChild) {
                                switch (StartPosition) {
@@ -1553,59 +1751,59 @@ namespace System.Windows.Forms {
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
-                       if (MaximizedBoundsChanged != null) {
-                               MaximizedBoundsChanged(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMaximumSizeChanged(EventArgs e) {
-                       if (MaximumSizeChanged != null) {
-                               MaximumSizeChanged(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMdiChildActivate(EventArgs e) {
-                       if (MdiChildActivate != null) {
-                               MdiChildActivate(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMenuComplete(EventArgs e) {
-                       if (MenuComplete != null) {
-                               MenuComplete(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMenuStart(EventArgs e) {
-                       if (MenuStart != null) {
-                               MenuStart(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMinimumSizeChanged(EventArgs e) {
-                       if (MinimumSizeChanged != null) {
-                               MinimumSizeChanged(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected override void OnPaint (PaintEventArgs pevent) {
                        base.OnPaint (pevent);
+
+                       if (size_grip != null) {
+                               size_grip.HandlePaint (this, pevent);
+                       }
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected override void OnResize(EventArgs e) {
                        base.OnResize(e);
 
-                       if (this.IsMdiChild && ParentForm != null) {
-                               ParentForm.PerformLayout();
-                               ParentForm.Size = ParentForm.Size;
-                       }
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -1617,8 +1815,8 @@ namespace System.Windows.Forms {
                protected override void OnTextChanged(EventArgs e) {
                        base.OnTextChanged (e);
 
-            if (mdi_container != null)
-                mdi_container.SetParentText(true);
+                       if (mdi_container != null)
+                               mdi_container.SetParentText(true);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -1641,6 +1839,24 @@ namespace System.Windows.Forms {
                                return ActiveMenu.ProcessCmdKey(ref msg, keyData);
                        }
 
+                       if (IsMdiChild) {
+                               switch (keyData)
+                               {
+                               case Keys.Control | Keys.F4:
+                               case Keys.Control | Keys.Shift | Keys.F4:
+                                       Close ();
+                                       return true;
+                               case Keys.Control | Keys.Tab:
+                               case Keys.Control | Keys.F6:
+                                       MdiParent.MdiContainer.ActivateNextChild ();
+                                       return true;
+                               case Keys.Control | Keys.Shift | Keys.Tab:
+                               case Keys.Control | Keys.Shift | Keys.F6:
+                                       MdiParent.MdiContainer.ActivatePreviousChild ();
+                                       return true;
+                               }
+                       }
+
                        return false;
                }
 
@@ -1684,7 +1900,11 @@ namespace System.Windows.Forms {
                        return SelectNextControl(ActiveControl, forward, true, true, true);
                }
 
+#if NET_2_0
+               [EditorBrowsable(EditorBrowsableState.Never)]
+#else
                [EditorBrowsable(EditorBrowsableState.Advanced)]
+#endif
                protected override void ScaleCore(float dx, float dy) {
                        try {
                                SuspendLayout();
@@ -1708,7 +1928,7 @@ namespace System.Windows.Forms {
                                }
 
                                /* Now scale our children */
-                               Control [] controls = child_controls.GetAllControls ();
+                               Control [] controls = Controls.GetAllControls ();
                                for (int i=0; i < controls.Length; i++) {
                                        controls[i].Scale(dx, dy);
                                }
@@ -1766,7 +1986,18 @@ namespace System.Windows.Forms {
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected override void SetVisibleCore(bool value) {
+                       is_changing_visible_state = true;
+                       has_been_visible = value || has_been_visible;
                        base.SetVisibleCore (value);
+                       is_changing_visible_state = false;
+                       
+#if NET_2_0
+                       // Shown event is only called once, the first time the form is made visible
+                       if (value && !shown_raised) {
+                               this.OnShown (EventArgs.Empty);
+                               shown_raised = true;
+                       }
+#endif
                }
 
                protected override void UpdateDefaultButton() {
@@ -1775,6 +2006,9 @@ namespace System.Windows.Forms {
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected override void WndProc(ref Message m) {
+#if debug
+                       Console.WriteLine(DateTime.Now.ToLongTimeString () + " Form {0} ({2}) received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString (), Text);
+#endif
 
                        if (window_manager != null && window_manager.HandleMessage (ref m)) {
                                return;
@@ -1783,7 +2017,7 @@ namespace System.Windows.Forms {
                        switch((Msg)m.Msg) {
                                case Msg.WM_DESTROY: {
                                        base.WndProc(ref m);
-                                       if (!is_recreating) {
+                                       if (!RecreatingHandle) {
                                                this.closing = true;
                                        }
                                        return;
@@ -1800,28 +2034,34 @@ namespace System.Windows.Forms {
                                                return;
                                        }
 
-                                       CancelEventArgs args = new CancelEventArgs ();
-
                                        if (mdi_container != null) {
                                                foreach (Form mdi_child in mdi_container.MdiChildren) {
-                                                       mdi_child.OnClosing (args);
+                                                       mdi_child.FireClosingEvents (CloseReason.MdiFormClosing);
                                                }
                                        }
 
                                        if (!is_modal) {
-                                               OnClosing (args);
-                                               if (!args.Cancel) {
+                                               if (!FireClosingEvents (CloseReason.UserClosing)) {
                                                        OnClosed (EventArgs.Empty);
+#if NET_2_0
+                                                       OnFormClosed (new FormClosedEventArgs (CloseReason.UserClosing));
+#endif
                                                        closing = true;
+                                                       Dispose ();
+                                               }
+                                               else {
+                                                       closing = false;
                                                }
-                                               Dispose ();
                                        } else {
-                                               OnClosing (args);
-                                               if (args.Cancel) {
+                                               if (FireClosingEvents (CloseReason.UserClosing)) {
                                                        DialogResult = DialogResult.None;
                                                        closing = false;
-                                               } else {
+                                               }
+                                               else {
                                                        OnClosed (EventArgs.Empty);
+#if NET_2_0
+                                                       OnFormClosed (new FormClosedEventArgs (CloseReason.UserClosing));
+#endif
                                                        closing = true;
                                                        Hide ();
                                                }
@@ -1841,7 +2081,7 @@ namespace System.Windows.Forms {
                                case Msg.WM_SYSCOMMAND: {
                                        // Let *Strips know the app's title bar was clicked
                                        if (XplatUI.IsEnabled (Handle))
-                                               ToolStripMenuTracker.FireAppClicked ();
+                                               ToolStripManager.FireAppClicked ();
                                                
                                        base.WndProc(ref m);
                                        break;
@@ -1850,14 +2090,16 @@ namespace System.Windows.Forms {
        
                                case Msg.WM_ACTIVATE: {
                                        if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
+                                               if (is_loaded) {
+                                                       SelectActiveControl ();
+
+                                                       if (ActiveControl != null && !ActiveControl.Focused)
+                                                               SendControlFocus (ActiveControl);
+                                               }
+
                                                OnActivated(EventArgs.Empty);
                                        } else {
                                                OnDeactivate(EventArgs.Empty);
-#if NET_2_0
-                                               // Let *Strips know the app lost focus
-                                               if (XplatUI.IsEnabled (Handle))
-                                                       ToolStripMenuTracker.FireAppFocusChanged ();
-#endif
                                        }
                                        return;
                                }
@@ -1872,12 +2114,34 @@ namespace System.Windows.Forms {
                                                ActiveControl.Focus();
                                                return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
                                        }
+                                       if (IsMdiContainer) {
+                                               mdi_container.SendFocusToActiveChild ();
+                                               return;
+                                       }
                                        base.WndProc(ref m);
                                        return;
                                }
 
                                // Menu drawing
-                               case Msg.WM_NCLBUTTONDOWN: {
+                case Msg.WM_NCHITTEST: {
+                                       if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
+                                               int x = LowOrder ((int)m.LParam.ToInt32 ());
+                                               int y = HighOrder ((int)m.LParam.ToInt32 ());
+
+                                               XplatUI.ScreenToMenu (ActiveMenu.Wnd.window.Handle, ref x, ref y);
+
+                                               // If point is under menu return HTMENU, it prevents Win32 to return HTMOVE.
+                                               if ((x > 0) && (y > 0) && (x < ActiveMenu.Rect.Width) && (y < ActiveMenu.Rect.Height)) {
+                                                       m.Result = new IntPtr ((int)HitTest.HTMENU);
+                                                       return;
+                                               }
+                                       }
+
+                                       base.WndProc (ref m);
+                                       return;
+                               }
+
+                case Msg.WM_NCLBUTTONDOWN: {
                                        if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
                                                ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
                                        }
@@ -1894,7 +2158,8 @@ namespace System.Windows.Forms {
                                        base.WndProc(ref m);
                                        return;
                                }
-                               case Msg.WM_NCLBUTTONUP: {
+
+                case Msg.WM_NCLBUTTONUP: {
                                        if (ActiveMaximizedMdiChild != null) {
                                                ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
                                                                LowOrder ((int)m.LParam.ToInt32 ()),
@@ -1920,6 +2185,7 @@ namespace System.Windows.Forms {
                                        }
                                        
                                        if (ActiveMaximizedMdiChild != null) {
+                                               XplatUI.RequestAdditionalWM_NCMessages (Handle, false, true);
                                                ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
                                                                LowOrder ((int)m.LParam.ToInt32 ()),
                                                                HighOrder ((int)m.LParam.ToInt32 ()));
@@ -1964,7 +2230,7 @@ namespace System.Windows.Forms {
                                                ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
 
                                                // Adjust for menu
-                                               ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
+                                               ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ClientSize.Width);
                                                Marshal.StructureToPtr(ncp, m.LParam, true);
                                        }
                                        DefWndProc(ref m);
@@ -1995,7 +2261,10 @@ namespace System.Windows.Forms {
                                                active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
                                                return;
                                        }
-                                       base.WndProc(ref m);
+#if NET_2_0
+                                       ToolStripManager.FireAppClicked ();
+#endif
+                                       base.WndProc (ref m);
                                        return;
                                }
 
@@ -2060,11 +2329,21 @@ namespace System.Windows.Forms {
                                case Msg.WM_MOUSEACTIVATE: {
                                        // Let *Strips know the form or another control has been clicked
                                        if (XplatUI.IsEnabled (Handle))
-                                               ToolStripMenuTracker.FireAppClicked ();
+                                               ToolStripManager.FireAppClicked ();
                                                
                                        base.WndProc (ref m);
                                        break;                          
                                }
+                               
+                               case Msg.WM_ACTIVATEAPP: {
+                                       // Let *Strips know the app lost focus
+                                       if (m.WParam == (IntPtr)0) 
+                                               if (XplatUI.IsEnabled (Handle))
+                                                       ToolStripManager.FireAppFocusChanged (this);
+                                                       
+                                       base.WndProc (ref m);
+                                       break;                          
+                               }
 #endif
 
                                default: {
@@ -2075,6 +2354,16 @@ namespace System.Windows.Forms {
                }
                #endregion      // Protected Instance Methods
 
+               internal override void FireEnter ()
+               {
+                       // do nothing - forms don't generate OnEnter
+               }
+
+               internal override void FireLeave ()
+               {
+                       // do nothing - forms don't generate OnLeave
+               }
+
                internal void RemoveWindowManager ()
                {
                        window_manager = null;
@@ -2100,19 +2389,99 @@ namespace System.Windows.Forms {
                }
                
                #region Events
-               public event EventHandler Activated;
-               public event EventHandler Closed;
-               public event CancelEventHandler Closing;
-               public event EventHandler Deactivate;
-               public event InputLanguageChangedEventHandler InputLanguageChanged;
-               public event InputLanguageChangingEventHandler InputLanguageChanging;
-               public event EventHandler Load;
-               public event EventHandler MaximizedBoundsChanged;
-               public event EventHandler MaximumSizeChanged;
-               public event EventHandler MdiChildActivate;
-               public event EventHandler MenuComplete;
-               public event EventHandler MenuStart;
-               public event EventHandler MinimumSizeChanged;
+               static object ActivatedEvent = new object ();
+               static object ClosedEvent = new object ();
+               static object ClosingEvent = new object ();
+               static object DeactivateEvent = new object ();
+               static object InputLanguageChangedEvent = new object ();
+               static object InputLanguageChangingEvent = new object ();
+               static object LoadEvent = new object ();
+               static object MaximizedBoundsChangedEvent = new object ();
+               static object MaximumSizeChangedEvent = new object ();
+               static object MdiChildActivateEvent = new object ();
+               static object MenuCompleteEvent = new object ();
+               static object MenuStartEvent = new object ();
+               static object MinimumSizeChangedEvent = new object ();
+
+               public event EventHandler Activated {
+                       add { Events.AddHandler (ActivatedEvent, value); }
+                       remove { Events.RemoveHandler (ActivatedEvent, value); }
+               }
+
+#if NET_2_0
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+#endif
+               public event EventHandler Closed {
+                       add { Events.AddHandler (ClosedEvent, value); }
+                       remove { Events.RemoveHandler (ClosedEvent, value); }
+               }
+
+#if NET_2_0
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+#endif
+               public event CancelEventHandler Closing {
+                       add { Events.AddHandler (ClosingEvent, value); }
+                       remove { Events.RemoveHandler (ClosingEvent, value); }
+               }
+
+               public event EventHandler Deactivate {
+                       add { Events.AddHandler (DeactivateEvent, value); }
+                       remove { Events.RemoveHandler (DeactivateEvent, value); }
+               }
+
+               public event InputLanguageChangedEventHandler InputLanguageChanged {
+                       add { Events.AddHandler (InputLanguageChangedEvent, value); }
+                       remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
+               }
+
+               public event InputLanguageChangingEventHandler InputLanguageChanging {
+                       add { Events.AddHandler (InputLanguageChangingEvent, value); }
+                       remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
+               }
+
+               public event EventHandler Load {
+                       add { Events.AddHandler (LoadEvent, value); }
+                       remove { Events.RemoveHandler (LoadEvent, value); }
+               }
+
+               public event EventHandler MaximizedBoundsChanged {
+                       add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
+                       remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
+               }
+
+               public event EventHandler MaximumSizeChanged {
+                       add { Events.AddHandler (MaximumSizeChangedEvent, value); }
+                       remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
+               }
+
+               public event EventHandler MdiChildActivate {
+                       add { Events.AddHandler (MdiChildActivateEvent, value); }
+                       remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
+               }
+
+#if NET_2_0
+               [Browsable (false)]
+#endif
+               public event EventHandler MenuComplete {
+                       add { Events.AddHandler (MenuCompleteEvent, value); }
+                       remove { Events.RemoveHandler (MenuCompleteEvent, value); }
+               }
+
+#if NET_2_0
+               [Browsable (false)]
+#endif
+               public event EventHandler MenuStart {
+                       add { Events.AddHandler (MenuStartEvent, value); }
+                       remove { Events.RemoveHandler (MenuStartEvent, value); }
+               }
+
+               public event EventHandler MinimumSizeChanged {
+                       add { Events.AddHandler (MinimumSizeChangedEvent, value); }
+                       remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
+               }
+
 
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
@@ -2123,6 +2492,7 @@ namespace System.Windows.Forms {
                #endregion      // Events
 
 #if NET_2_0
+               [SettingsBindable (true)]
                public override string Text {
                        get {
                                return base.Text;
@@ -2133,6 +2503,7 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [SettingsBindable (true)]
                public new Point Location {
                        get {
                                return base.Location;
@@ -2143,13 +2514,153 @@ namespace System.Windows.Forms {
                        }
                }
 
-               public event FormClosingEventHandler FormClosing;
-               public event FormClosedEventHandler FormClosed;
+               static object FormClosingEvent = new object ();
+               static object FormClosedEvent = new object ();
+               static object HelpButtonClickedEvent = new object ();
+               static object ResizeEndEvent = new object ();
+               static object ResizeBeginEvent = new object ();
+               static object RightToLeftLayoutChangedEvent = new object ();
+               static object ShownEvent = new object ();
+
+               [Browsable (true)]
+               [EditorBrowsable (EditorBrowsableState.Always)]
+               public new event EventHandler AutoSizeChanged {
+                       add { base.AutoSizeChanged += value; }
+                       remove { base.AutoSizeChanged -= value; }
+               }
+
+               [Browsable (true)]
+               [EditorBrowsable (EditorBrowsableState.Always)]
+               public new event EventHandler AutoValidateChanged {
+                       add { base.AutoValidateChanged += value; }
+                       remove { base.AutoValidateChanged -= value; }
+               }
+
+               public event FormClosingEventHandler FormClosing {
+                       add { Events.AddHandler (FormClosingEvent, value); }
+                       remove { Events.RemoveHandler (FormClosingEvent, value); }
+               }
+
+               public event FormClosedEventHandler FormClosed {
+                       add { Events.AddHandler (FormClosedEvent, value); }
+                       remove { Events.RemoveHandler (FormClosedEvent, value); }
+               }
+
+               [Browsable (true)]
+               [EditorBrowsable (EditorBrowsableState.Always)]
+               public event CancelEventHandler HelpButtonClicked {
+                       add { Events.AddHandler (HelpButtonClickedEvent, value); }
+                       remove { Events.RemoveHandler (HelpButtonClickedEvent, value); }
+               }
+
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public new event EventHandler MarginChanged {
+                       add { base.MarginChanged += value; }
+                       remove { base.MarginChanged -= value; }
+               }
+
+               public event EventHandler RightToLeftLayoutChanged {
+                       add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
+                       remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
+               }
+
+               public event EventHandler ResizeBegin {
+                       add { Events.AddHandler (ResizeBeginEvent, value); }
+                       remove { Events.RemoveHandler (ResizeBeginEvent, value); }
+               }
+
+               public event EventHandler ResizeEnd {
+                       add { Events.AddHandler (ResizeEndEvent, value); }
+                       remove { Events.RemoveHandler (ResizeEndEvent, value); }
+               }
+
+               public event EventHandler Shown {
+                       add { Events.AddHandler (ShownEvent, value); }
+                       remove { Events.RemoveHandler (ShownEvent, value); }
+               }
+
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public new event EventHandler TabStopChanged {
+                       add { base.TabStopChanged += value; }
+                       remove { base.TabStopChanged -= value; }
+               }
+
+               protected override void OnBackgroundImageChanged (EventArgs e)
+               {
+                       base.OnBackgroundImageChanged (e);
+               }
+
+               protected override void OnBackgroundImageLayoutChanged (EventArgs e)
+               {
+                       base.OnBackgroundImageLayoutChanged (e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected override void OnEnabledChanged (EventArgs e)
+               {
+                       base.OnEnabledChanged (e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected override void OnEnter (EventArgs e)
+               {
+                       base.OnEnter (e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnFormClosed (FormClosedEventArgs e) {
+                       FormClosedEventHandler eh = (FormClosedEventHandler)(Events[FormClosedEvent]);
+                       if (eh != null)
+                               eh (this, e);
+               }
                
+               // Consider calling FireClosingEvents instead of calling this directly.
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected virtual void OnFormClosing (FormClosingEventArgs e)
                {
-                       if (FormClosing != null)
-                               FormClosing (this, e);
+                       FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);
+                       if (eh != null)
+                               eh (this, e);
+               }
+
+               [MonoTODO ("Not hooked up to event")]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnHelpButtonClicked (CancelEventArgs e)
+               {
+                       CancelEventHandler eh = (CancelEventHandler)(Events[HelpButtonClickedEvent]);
+                       if (eh != null)
+                               eh (this, e);
+               }
+
+               protected override void OnLayout (LayoutEventArgs levent)
+               {
+                       base.OnLayout (levent);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnResizeBegin (EventArgs e)
+               {
+                       EventHandler eh = (EventHandler) (Events [ResizeBeginEvent]);
+                       if (eh != null)
+                               eh (this, e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnResizeEnd (EventArgs e)
+               {
+                       EventHandler eh = (EventHandler) (Events [ResizeEndEvent]);
+                       if (eh != null)
+                               eh (this, e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnShown (EventArgs e)
+               {
+                       EventHandler eh = (EventHandler) (Events [ShownEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 #endif
        }