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.
Unfortunately, activation email could not send to your email. Please try again.

How to provide padding to the sides of the layout rect

 

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.NET] ' 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

Article ID: Published Date: Last Revised Date: Platform: Control:
1177 04/30/2011 07/10/2014 Windows Forms XPToolbar
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.