)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to provide padding to the sides of the layout rect in WinForms CardLayout?

Platform: WinForms |
Control: CardLayout |
Published Date: February 10, 2020 |
Last Revised Date: February 10, 2020

Padding

While the default "layout rect" is the whole client rectangle of the container control, you can provide some padding to the sides by specifying a different layout rect via the CustomLayoutBounds property. But if your container is resizable (most probably), then this property’s value should keep changing as the container’s bounds change.

You can do so by first turning off AutoLayout on the manager, listening to the container’s layout event, setting the new layout rect from within the handler, and then manually triggering the layout, as follows:

C#

// Turn off AutoLayout on the layout manager and trigger the layout manually, since we will provide custom layout bounds, below.
// Listen to the container’s Layout event and do the following:
private void panel1_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
{
   // If the container control is getting resized...
   if(e.AffectedControl == this.panel1)
   {
      // Give some padding to the sides of the layout rect.
      Rectangle clientRectangle = this.panel1.ClientRectangle;
      clientRectangle.Inflate(-40, -40);
      // Provide the custom layout bounds and trigger the layout.    
      this.cardLayout1.CustomLayoutBounds = clientRectangle;
      this.cardLayout1.LayoutContainer();
   }
}

VB

' Turn off AutoLayout on the layout manager and trigger the layout manually, since we will provide custom layout bounds, below.
' Listen to the container’s Layout event and do the following:
Private  Sub panel1_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs
   ' If the container control is getting resized...
   If e.AffectedControl = Me.panel1 Then
      ' Give some padding to the sides of the layout rect.
      Dim clientRectangle As Rectangle = Me.panel1.ClientRectangle
      clientRectangle.Inflate(-40, -40)
      ' Provide the custom layout bounds and trigger the layout.
      Me.cardLayout1.CustomLayoutBounds = clientRectangle
      Me.cardLayout1.LayoutContainer()
   End If
End Sub

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon