diff --git a/source/IPAddressControl.cs b/source/IPAddressControl.cs index c906b24..9e8adc4 100644 --- a/source/IPAddressControl.cs +++ b/source/IPAddressControl.cs @@ -201,6 +201,23 @@ public override Size MinimumSize get { return CalculateMinimumSize(); } } + [Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced), + DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public int PreferredHeight + { + get + { + int height = FontHeight; + + if (BorderStyle != BorderStyle.None) + { + height += SystemInformation.BorderSize.Height * 4 + 3; + } + + return height; + } + } + [Browsable(true)] public bool ReadOnly { @@ -597,11 +614,11 @@ private Size CalculateMinimumSize() { case BorderStyle.Fixed3D: minimumSize.Width += 6; - minimumSize.Height += (GetSuggestedHeight() - minimumSize.Height); + minimumSize.Height += (PreferredHeight - minimumSize.Height); break; case BorderStyle.FixedSingle: minimumSize.Width += 4; - minimumSize.Height += (GetSuggestedHeight() - minimumSize.Height); + minimumSize.Height += (PreferredHeight - minimumSize.Height); break; } @@ -626,19 +643,6 @@ private void Cleanup() _fieldControls = null; } - private int GetSuggestedHeight() - { - int height = 0; - using (TextBox reference = new TextBox()) - { - reference.AutoSize = true; - reference.BorderStyle = BorderStyle; - reference.Font = Font; - height = reference.Height; - } - return height; - } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806", Justification = "What should be done if ReleaseDC() doesn't work?")] private static NativeMethods.Textmetric GetTextMetrics(IntPtr hwnd, Font font) {