Apply fix for 2839 from Michael Mudge
authorMiguel de Icaza <miguel@gnome.org>
Fri, 13 Jan 2012 23:58:53 +0000 (18:58 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 13 Jan 2012 23:58:53 +0000 (18:58 -0500)
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs

index e824ff1fe48e051a600193e704291abdf5d1c16f..cc60cc257e7079cb1f7fd581acd102e6e75218cf 100644 (file)
@@ -237,8 +237,8 @@ namespace System.Windows.Forms
                                if (value != auto_size) {
                                        auto_size = value;
                                        if (auto_size) {
-                                               if (PreferredHeight != ClientSize.Height) {
-                                                       ClientSize = new Size(ClientSize.Width, PreferredHeight);
+                                               if (PreferredHeight != Height) {
+                                                       Height = PreferredHeight;
                                                }
                                        }
                                }
@@ -466,14 +466,16 @@ namespace System.Windows.Forms
                [Browsable(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [EditorBrowsable(EditorBrowsableState.Advanced)]
+               // This returns the preferred outer height, not the client height.
                public int PreferredHeight {
                        get {
+                               int clientDelta = Height - ClientSize.Height;
                                if (BorderStyle != BorderStyle.None)
-                                       return Font.Height + 7;
+                                       return Font.Height + 7 + clientDelta;
 
                                // usually in borderless mode the top margin is 0, but
                                // try to access it, in case it was set manually, as ToolStrip* controls do
-                               return Font.Height + TopMargin;
+                               return Font.Height + TopMargin + clientDelta;
                        }
                }
 
@@ -993,7 +995,7 @@ namespace System.Windows.Forms
                        base.OnFontChanged (e);
 
                        if (auto_size && !document.multiline) {
-                               if (PreferredHeight != ClientSize.Height) {
+                               if (PreferredHeight != Height) {
                                        Height = PreferredHeight;
                                }
                        }
@@ -1762,8 +1764,8 @@ namespace System.Windows.Forms
                {
                        if (!richtext) {
                                if (!document.multiline) {
-                                       if (PreferredHeight != ClientSize.Height) {
-                                               ClientSize = new Size (ClientSize.Width, PreferredHeight);
+                                       if (PreferredHeight != Height) {
+                                               Height = PreferredHeight;
                                        }
                                }
                        }