rendered paste bodyIndex: System.Windows.Forms/Control.cs
===================================================================
--- System.Windows.Forms/Control.cs (revision 74849)
+++ System.Windows.Forms/Control.cs (working copy)
@@ -4282,11 +4282,16 @@
}
if (IsHandleCreated) {
- XplatUI.SetVisible(Handle, is_visible, true);
- // Explicitly move Toplevel windows to where we want them;
- // apparently moving unmapped toplevel windows doesn't work
- if (is_visible && (this is Form)) {
- XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
+ XplatUI.SetVisible (Handle, is_visible, true);
+
+ if (is_visible && this is Form) {
+ // If we are Min or Max, we won't get a WM_SHOWWINDOW from SetWindowState,
+ // so we need to manually create our children, and set them visible
+ // (This normally happens in WmShowWindow.)
+ if ((this as Form).WindowState != FormWindowState.Normal)
+ OnVisibleChanged (EventArgs.Empty);
+ else
+ XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
}
}
else {
@@ -4901,13 +4906,14 @@
private void WmShowWindow (ref Message m) {
if (m.WParam.ToInt32() != 0) {
- CreateControl ();
- /* if we're being shown, make sure our child controls all have their handles created */
- Control [] controls = child_controls.GetAllControls ();
- for (int i=0; i<controls.Length; i++) {
- if (controls [i].is_visible) {
- controls [i].CreateControl ();
- XplatUI.SetParent(controls[i].Handle, window.Handle);
+ if (m.LParam.ToInt32 () == 0) {
+ CreateControl ();
+
+ // Make sure all our children are properly parented to us
+ Control [] controls = child_controls.GetAllControls ();
+ for (int i=0; i<controls.Length; i++) {
+ if (controls [i].is_visible && controls[i].IsHandleCreated)
+ XplatUI.SetParent(controls[i].Handle, window.Handle);
}
}
}
@@ -4923,7 +4929,13 @@
}
}
- if (is_toplevel || (this is Form && ((Form) this).IsMdiChild)) /* XXX make sure this works for mdi forms */
+ // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
+ if (this is Form) {
+ Form f = (Form)this;
+
+ if (f.IsMdiChild || f.WindowState == FormWindowState.Normal) /* XXX make sure this works for mdi forms */
+ OnVisibleChanged(EventArgs.Empty);
+ } else if (is_toplevel)
OnVisibleChanged(EventArgs.Empty);
}
@@ -5619,6 +5631,9 @@
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnVisibleChanged(EventArgs e) {
+ if (!this.Created)
+ this.CreateControl ();
+
EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
if (eh != null)
eh (this, e);
Index: System.Windows.Forms/Form.cs
===================================================================
--- System.Windows.Forms/Form.cs (revision 74849)
+++ System.Windows.Forms/Form.cs (working copy)
@@ -87,11 +87,11 @@
private bool is_loaded;
internal bool is_changing_visible_state;
internal bool has_been_visible;
+ private bool shown_raised; // The shown event is only raised once
#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
@@ -1076,7 +1076,8 @@
[MWFCategory("Layout")]
public FormWindowState WindowState {
get {
- if (IsHandleCreated) {
+ // Don't actually rely on the WM until we've been shown
+ if (IsHandleCreated && shown_raised) {
if (window_manager != null)
return window_manager.GetWindowState ();
@@ -1092,7 +1093,7 @@
set {
FormWindowState old_state = window_state;
window_state = value;
- if (IsHandleCreated) {
+ if (IsHandleCreated && shown_raised) {
if (window_manager != null) {
window_manager.SetWindowState (old_state, value);
@@ -1261,9 +1262,6 @@
if (HelpButton && !MaximizeBox && !MinimizeBox) {
cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
}
-
- if (VisibleInternal)
- cp.Style |= (int)WindowStyles.WS_VISIBLE;
if (opacity < 1.0 || TransparencyKey != Color.Empty) {
cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
@@ -2059,6 +2057,10 @@
is_changing_visible_state = true;
has_been_visible = value || has_been_visible;
base.SetVisibleCore (value);
+
+ if (value && this.WindowState != FormWindowState.Normal)
+ XplatUI.SendMessage (this.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
+
is_changing_visible_state = false;
}
@@ -2078,13 +2080,14 @@
PerformLayout ();
ThemeEngine.Current.ManagedWindowSetButtonLocations (window_manager);
}
-#if NET_2_0
+
// Shown event is only called once, the first time the form is made visible
if (value && !shown_raised) {
+#if NET_2_0
this.OnShown (EventArgs.Empty);
+#endif
shown_raised = true;
}
-#endif
}
protected override void UpdateDefaultButton() {