Merge pull request #943 from ermshiperete/bug-novell-325669
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ComboBox.cs
index 88f50eff78424a62b9b1e4d9d17021330a9c0d6a..fad6981b745964226a9ff363374068cfde4946ef 100644 (file)
@@ -2000,8 +2000,10 @@ namespace System.Windows.Forms
                                        if (index == owner.SelectedIndex) {
                                                if (owner.textbox_ctrl == null)
                                                        owner.Refresh ();
-                                               else
-                                                       owner.textbox_ctrl.SelectedText = value.ToString ();
+                                               else {
+                                                       owner.textbox_ctrl.Text = value.ToString ();
+                                                       owner.textbox_ctrl.SelectAll ();
+                                               }
                                        }
                                }
                        }
@@ -2313,7 +2315,16 @@ namespace System.Windows.Forms
                                        return owner.Focused;
                                }
                        }
-                       
+                       protected override void Dispose(bool disposing)
+                       {
+                               if (disposing ) {
+                                       // Prevents corruption of combobox text by disposed object
+                                       owner.EnabledChanged -= OwnerEnabledChangedHandler;
+                                       owner.LostFocus -= OwnerLostFocusHandler;
+                               }
+                               base.Dispose(disposing);
+                       }
+
                        internal override bool ActivateOnShow { get { return false; } }
                }
 
@@ -2522,12 +2533,14 @@ namespace System.Windows.Forms
                                                vscrollbar_ctrl.Value = hli;
                                        }
                                }
-                               
-                               Size = new Size (width, height);
-                               textarea_drawable = ClientRectangle;
-                               textarea_drawable.Width = width;
-                               textarea_drawable.Height = height;
-                               
+
+                               var borderWidth = Hwnd.GetBorderWidth (CreateParams);
+                               var borderAdjustment = dropdown_style == ComboBoxStyle.Simple ? new Size (0, 0) :
+                                       new Size (borderWidth.top + borderWidth.bottom, borderWidth.left + borderWidth.right);
+                               Size = new Size (width, height + borderAdjustment.Height);
+                               textarea_drawable = new Rectangle (ClientRectangle.Location,
+                                       new Size (width - borderAdjustment.Width, height));
+
                                if (vscrollbar_ctrl != null && show_scrollbar)
                                        textarea_drawable.Width -= vscrollbar_ctrl.Width;
 
@@ -2755,6 +2768,10 @@ namespace System.Windows.Forms
                                HighlightedIndex = owner.SelectedIndex;
 
                                CalcListBoxArea ();
+                               // If the listbox would extend below the screen, move it above the textbox.
+                               Rectangle scrn_rect = Screen.FromControl (owner).Bounds;
+                               if (this.Location.Y + this.Height >= scrn_rect.Bottom)
+                                       this.Location = new Point (this.Location.X, this.Location.Y - (this.Height + owner.TextArea.Height));
                                Show ();
 
                                Refresh ();