The best place to ensure a particular height/width for you control is in the SetBoundsCore override of your Control, as follows:
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
int prefHeight = this.GetPreferredHeight();
// Ensure that the height is atleast as big as prefHeight
if(height < prefHeight)
height = prefHeight;
base.SetBoundsCore(x, y, width, height, specified);
}
Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
Dim prefHeight As Integer = Me.GetPreferredHeight()
’ Ensure that the height is atleast as big as prefHeight
If height < prefHeight Then
height = prefHeight
End If
MyBase.SetBoundsCore(x, y, width, height, specified)
End Sub
Share with