WinForms

Code Examples Upgrade Guide User Guide Demos Support Forums Download
  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class GridBagLayout

    Show / Hide Table of Contents

    Class GridBagLayout

    Represents the LayoutManager that performs GridBagLayout.

    Inheritance
    System.Object
    LayoutManager
    GridBagLayout
    Implements
    System.ComponentModel.IExtenderProvider
    ILayoutManager
    System.ComponentModel.ISupportInitialize
    Inherited Members
    LayoutManager.initializing
    LayoutManager.preferredSizes
    LayoutManager.minimumSizes
    LayoutManager.MakeDirty()
    LayoutManager.OnContainerControlChanged(EventArgs)
    LayoutManager.ResetCustomLayoutBounds()
    LayoutManager.ShouldSerializeCustomLayoutBounds()
    LayoutManager.Dispose(Boolean)
    LayoutManager.BeginInit()
    LayoutManager.EndInit()
    LayoutManager.CanExtend(Object)
    LayoutManager.GetPreferredSize(Control)
    LayoutManager.ForcePreferredAndMinimumsSize()
    LayoutManager.GetMinimumSize(Control)
    LayoutManager.SetMinimumSize(Control, Size)
    LayoutManager.GetDynamicSize(Control, LayoutInformationType, Size)
    LayoutManager.OnProvideLayoutInformation(ProvideLayoutInformationEventArgs)
    LayoutManager.OnControlRemoved(Object, ControlEventArgs)
    LayoutManager.OnDockStyleChanged(Object, EventArgs)
    LayoutManager.GetControls()
    LayoutManager.GetBounds()
    LayoutManager.AdjustHeightForMargins(Int32)
    LayoutManager.AdjustWidthForMargins(Int32)
    LayoutManager.IsVisible(Control)
    LayoutManager.IsInit()
    LayoutManager.GetAutoLabel(Control)
    LayoutManager.ShouldLayoutAutoLabel(AutoLabel)
    LayoutManager.LoadingDocument
    LayoutManager.DesignerInTransaction
    LayoutManager.DesignerHost
    LayoutManager.ComponentDesigner
    LayoutManager.ContainerControl
    LayoutManager.CustomLayoutBounds
    LayoutManager.UseControlCollectionPosition
    LayoutManager.LayoutControls
    LayoutManager.AutoLayout
    LayoutManager.LeftMargin
    LayoutManager.HorzNearMargin
    LayoutManager.RightMargin
    LayoutManager.HorzFarMargin
    LayoutManager.TopMargin
    LayoutManager.BottomMargin
    LayoutManager.ContainerControlChanged
    LayoutManager.ProvideLayoutInformation
    Namespace: Syncfusion.Windows.Forms.Tools
    Assembly: Syncfusion.Shared.Base.dll
    Syntax
    public class GridBagLayout : LayoutManager, IExtenderProvider, ILayoutManager, ISupportInitialize
    Remarks

    The GridBagLayout manager creates and manages a grid within the container's layout bounds. Each column and row in this grid can be of different sizes and a component can span more than one cell.

    Each component can be assigned weights to determine how to distribute extra space between components. A component can also be anchored to a border / corner of its virtual grid cell. It can also fill its cell.

    Note that if you want the child components to be laid out purely based on their weights, set their preferred sizes to be (0,0), specify a non-zero weightX and weigthY, and set their Fill mode to FillMode.Both.

    The GridBagConstraints structure specifies all the above constraints associated with a component. Use the SetConstraints method to set the constraints for each component. To exclude a component from layout, call SetConstraints with NULL constraints. Each component has a constraint, which means that there is potential for conflicts in size and boundaries between components. Make sure to manually test the layout design to determine that it behaves appropriately.

    Examples

    The following example shows you how to initialize a GridBagLayout manager with a container control and its children:

                // Binding a control to the GridBagLayout  manager programmatically:
                this.gridBagLayout1 = new GridBagLayout();
    
                // Set the container control; all the child controls of this container control are
                // automatically registered as children with the manager:
                this.gridBagLayout1.ContainerControl = this.panel1;
    
                this.gridBagLayout1.SetConstraints(
                    this.button1,
                    new GridBagConstraints(0, 0, 3, 1, 1, 0.2, AnchorTypes.Center, FillType.Both, new Insets(0, 0, 0, 0), 0, 0, false)
                    );
                this.gridBagLayout1.SetConstraints(
                    this.button2,
                    new GridBagConstraints(0, 1, 1, 3, 0.2, 0.6, AnchorTypes.Center, FillType.Both, new Insets(0, 0, 0, 0), 0, 0, false)
                    );
    
                // Exclude button3 from layout:
                this.gridBagLayout1.SetConstraints(this.button3, GridBagConstraints.Empty);
    
                // Modify an exisiting constraint:
                GridBagConstraints constraints1 = this.gridBagLayout1.GetConstraintsRef(this.button1);
                constraints1.Fill = FillType.Horizontal;
    
                // You can prevent automatic layout during the layout event.
                // If you decide to do so, make sure to call gridBagLayout1.LayoutContainer manually:
                // this.gridBagLayout1.AutoLayout = false;

    Also take a look at the project in Tools/Samples/Quick Start/LayoutManager for an example.

    Constructors

    GridBagLayout()

    Overloaded. Creates a new instance of the GridBagLayout class and sets its defaults.

    Declaration
    public GridBagLayout()

    GridBagLayout(IContainer)

    Creates a new instance of the GridBagLayout class and adds itself to the specified container.

    Declaration
    public GridBagLayout(IContainer container)
    Parameters
    Type Name Description
    System.ComponentModel.IContainer container

    The logical ContainerControl parent into which to add itself.

    Remarks

    This constructor is used by the design-time to add a component to the form's IContainer field so that it gets Disposed when the form gets Disposed.

    Note that this is not the same as the LayoutManager 's ContainerControl.

    GridBagLayout(Control)

    Creates a new instance of the GridBagLayout class and sets its ContainerControl.

    Declaration
    public GridBagLayout(Control container)
    Parameters
    Type Name Description
    System.Windows.Forms.Control container

    The logical ContainerControl parent into which to add itself.

    Fields

    columnWeights

    Largest weight in each column.

    Declaration
    public double[] columnWeights
    Field Value
    Type Description
    System.Double[]

    columnWidths

    Largest minimum width in each column.

    Declaration
    public int[] columnWidths
    Field Value
    Type Description
    System.Int32[]

    MaxGridSize

    Declaration
    public const int MaxGridSize = 512
    Field Value
    Type Description
    System.Int32

    MinimumSize

    Declaration
    protected static int MinimumSize
    Field Value
    Type Description
    System.Int32

    MinSize

    Declaration
    public const int MinSize = 1
    Field Value
    Type Description
    System.Int32

    noFillSizes

    Declaration
    protected Hashtable noFillSizes
    Field Value
    Type Description
    System.Collections.Hashtable

    PreferredSize

    Declaration
    protected static int PreferredSize
    Field Value
    Type Description
    System.Int32

    rowHeights

    Largest minimum height in each row.

    Declaration
    public int[] rowHeights
    Field Value
    Type Description
    System.Int32[]

    rowWeights

    Largest weight in each row.

    Declaration
    public double[] rowWeights
    Field Value
    Type Description
    System.Double[]

    Methods

    AddLayoutComponent(Control, Object)

    Adds a component to the child layout list.

    Declaration
    public override void AddLayoutComponent(Control control, object constraints)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    The control to add to the layout list.

    System.Object constraints

    The GridBagConstraints associated with this component.

    Overrides
    LayoutManager.AddLayoutComponent(Control, Object)
    Remarks

    If the second argument is not a GridBagConstraints , an exception will be thrown.

    AdjustForGravity(GridBagConstraints, ref Rectangle)

    Declaration
    protected void AdjustForGravity(GridBagConstraints constraints, ref Rectangle r)
    Parameters
    Type Name Description
    GridBagConstraints constraints
    System.Drawing.Rectangle r

    GetConstraints(Control)

    Returns the constraints associated with the specified control.

    Declaration
    public GridBagConstraints GetConstraints(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    The control whose constraints to retrieve.

    Returns
    Type Description
    GridBagConstraints

    A clone of the stored constraints object.

    Remarks

    The returned value is a clone which can be used independently by itself. The changes made to the returned instance will not have any effect on the stored constraints. Use GetConstraintsRef(Control) to get hold of the actual constraints object that is used by the manager.

    GetConstraintsRef(Control)

    Returns a reference to the constraints associated with the specified control.

    Declaration
    public GridBagConstraints GetConstraintsRef(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    The control with constraints to retrieve.

    Returns
    Type Description
    GridBagConstraints

    A reference to the actual constraints object.

    Remarks

    This is the actual object where the manager stores the constraints for the control. Hence, making changes to the returned object will affect the layout logic.

    GetLayoutDimensions()

    Returns the row and column dimensions of the current layout.

    Declaration
    [CLSCompliant(false)]
    public int[][] GetLayoutDimensions()
    Returns
    Type Description
    System.Int32[][]

    A 2D integer array containing the dimensions.

    GetLayoutInfo(Int32)

    Declaration
    protected GridBagLayoutInfo GetLayoutInfo(int sizeflag)
    Parameters
    Type Name Description
    System.Int32 sizeflag
    Returns
    Type Description
    GridBagLayoutInfo

    GetLayoutOrigin()

    Returns the top-left origin of the virtual grid in the current layout.

    Declaration
    public Point GetLayoutOrigin()
    Returns
    Type Description
    System.Drawing.Point

    A point representing the top-left position.

    GetLayoutWeights()

    Returns the row and column weights of the current layout.

    Declaration
    [CLSCompliant(false)]
    public double[][] GetLayoutWeights()
    Returns
    Type Description
    System.Double[][]

    A 2D integer array containing the weights.

    GetLocation(Int32, Int32)

    Returns the cell in the virtual grid (as a point) given a location.

    Declaration
    public Point GetLocation(int x, int y)
    Parameters
    Type Name Description
    System.Int32 x

    The x coordinate of the location.

    System.Int32 y

    The y coordinate of the location.

    Returns
    Type Description
    System.Drawing.Point

    A Point representing the virtual grid cell.

    GetMinSize(GridBagLayoutInfo)

    Declaration
    protected Size GetMinSize(GridBagLayoutInfo info)
    Parameters
    Type Name Description
    GridBagLayoutInfo info
    Returns
    Type Description
    System.Drawing.Size

    GetStaticMinimumSize(Control)

    Declaration
    protected override Size GetStaticMinimumSize(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control
    Returns
    Type Description
    System.Drawing.Size
    Overrides
    LayoutManager.GetStaticMinimumSize(Control)

    GetStaticPreferredSize(Control)

    Declaration
    protected override Size GetStaticPreferredSize(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control
    Returns
    Type Description
    System.Drawing.Size
    Overrides
    LayoutManager.GetStaticPreferredSize(Control)

    LayoutContainer()

    Overridden. See LayoutContainer().

    Declaration
    public override void LayoutContainer()
    Overrides
    LayoutManager.LayoutContainer()

    LayoutGridBag()

    Declaration
    protected void LayoutGridBag()

    MinimumLayoutSize()

    Overridden. See MinimumLayoutSize().

    Declaration
    public override Size MinimumLayoutSize()
    Returns
    Type Description
    System.Drawing.Size

    Returns the MinimumSize of the ContainerControl.

    Overrides
    LayoutManager.MinimumLayoutSize()

    OnControlAdded(Object, ControlEventArgs)

    Declaration
    protected override void OnControlAdded(object sender, ControlEventArgs e)
    Parameters
    Type Name Description
    System.Object sender
    System.Windows.Forms.ControlEventArgs e
    Overrides
    LayoutManager.OnControlAdded(Object, ControlEventArgs)

    PreferredLayoutSize()

    Overridden. See PreferredLayoutSize().

    Declaration
    public override Size PreferredLayoutSize()
    Returns
    Type Description
    System.Drawing.Size

    Reutrns the preferred size of the Container control.

    Overrides
    LayoutManager.PreferredLayoutSize()

    RemoveLayoutComponent(Control)

    Overridden. See RemoveLayoutComponent(Control).

    Declaration
    public override void RemoveLayoutComponent(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control
    Overrides
    LayoutManager.RemoveLayoutComponent(Control)

    ResetConstraints(Control)

    Declaration
    protected void ResetConstraints(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    ResetLayoutInfo()

    Overridden. See ResetLayoutInfo().

    Declaration
    protected override void ResetLayoutInfo()
    Overrides
    LayoutManager.ResetLayoutInfo()

    ResetMinimumSize(Control)

    Overridden. See ResetMinimumSize(Control).

    Declaration
    public override void ResetMinimumSize(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    The Control which MinimumSize to be reset.

    Overrides
    LayoutManager.ResetMinimumSize(Control)

    ResetPreferredSize(Control)

    Overridden. See ResetPreferredSize(Control).

    Declaration
    public override void ResetPreferredSize(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    The control which PreferredSize to be reset.

    Overrides
    LayoutManager.ResetPreferredSize(Control)

    SetConstraints(Control, GridBagConstraints)

    Specifies the constraints associated with the specified control.

    Declaration
    public void SetConstraints(Control control, GridBagConstraints value)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    The control for which to set the constraints.

    GridBagConstraints value

    The constraints of the control. Or NULL to remove the control from the layout list.

    Remarks

    Passing a NULL value will actually remove the component from the layout list.

    SetPreferredSize(Control, Size)

    Overridden. See SetPreferredSize(Control, Size).

    Declaration
    public override void SetPreferredSize(Control control, Size value)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control

    The control to associate the preferred size with.

    System.Drawing.Size value

    The preferred size of the control.

    Overrides
    LayoutManager.SetPreferredSize(Control, Size)

    ShouldSerializeConstraints(Control)

    Declaration
    protected bool ShouldSerializeConstraints(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control
    Returns
    Type Description
    System.Boolean

    ShouldSerializeMinimumSize(Control)

    Indicates whether to serialize the MinimumSize property.

    Declaration
    public override bool ShouldSerializeMinimumSize(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control
    Returns
    Type Description
    System.Boolean
    Overrides
    LayoutManager.ShouldSerializeMinimumSize(Control)

    ShouldSerializePreferredSize(Control)

    Indicates whether to serialize the PreferredSize property.

    Declaration
    public override bool ShouldSerializePreferredSize(Control control)
    Parameters
    Type Name Description
    System.Windows.Forms.Control control
    Returns
    Type Description
    System.Boolean
    Overrides
    LayoutManager.ShouldSerializePreferredSize(Control)

    Implements

    System.ComponentModel.IExtenderProvider
    ILayoutManager
    System.ComponentModel.ISupportInitialize
    Back to top Generated by DocFX
    Copyright © 2001 - 2023 Syncfusion Inc. All Rights Reserved