Skip to content

Commit

Permalink
add PreferredHeight from TextBoxBase open source code
Browse files Browse the repository at this point in the history
remove kludge that was GetSuggestedHeight()
  • Loading branch information
m66n committed Mar 17, 2016
1 parent 0fc5f1d commit c7412cb
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions source/IPAddressControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
{
Expand Down

0 comments on commit c7412cb

Please sign in to comment.