Grid - ahatornn/clforms GitHub Wiki

Grid

ClForms.Elements.Grid
Defines a flexible grid area that consists of columns and rows

public class Grid: MultipleContentControl, IElementStyle<Grid>

Inheritance Control -> ContentControl -> MultipleContentControl -> Grid
Derived IElementStyle<Grid>

Examples

The following example demonstrates how to create a grid. In this case, the grid defines two ColumnDefinition elements and two RowDefinition elements that host child content.

var grid = new Grid
{
    Width = 70,
    Margin = new Thickness(0, 1),
    ShowGridLine = true,
    BorderColor = Color.Yellow,
};
grid.RowDefinitions.Add(new RowDefinition(SizeType.Absolute, 3));
grid.RowDefinitions.Add(new RowDefinition(SizeType.AutoSize));

grid.ColumnDefinitions.Add(new ColumnDefinition(SizeType.Percent, 60));
grid.ColumnDefinitions.Add(new ColumnDefinition(SizeType.Percent, 40));

var lb1 = new Label
{
    WordWrap = true,
    Text = "Panel is a simple control using to group collections of controls…",
};
grid.AddContent(lb1, column: 0, row: 0, columnSpan: 2);

var targetPanel = new Panel()
{
    VerticalContentAlignment = VerticalAlignment.Center,
    HorizontalContentAlignment = HorizontalAlignment.Center,
    Background = Color.DarkMagenta,
};
targetPanel.AddContent(new Label("Content")
{
    Background = Color.Magenta,
    Foreground = Color.White,
});
grid.AddContent(targetPanel, column: 0, row: 1);

var descriptionLabel = new Label("Let's check how to…")
{
    Margin = new Thickness(1, 0, 0, 0),
    WordWrap = true,
};
grid.AddContent(descriptionLabel, 1, 1);

Remarks

A Grid contains a collection of Control objects, which are in the cast to list Grid control.
Child elements of a Grid are drawn in the order in which they appear in markup or code. As a consequence, layered order (also known as z-order) can be achieved when elements share the same coordinates.

Constructors

Syntax Description
Grid() Initialize a new Grid instance

Properties

Name Type Description
AutoSize bool Gets or sets a value indicating whether the control is resized in accordance with its contents
Background Color Gets or sets a brush that describes the background of a control
BackgroundIsTransparent bool Gets a value indicating whether the Background has Color.NotSet
BorderChars GridSpanBorderChars Gets or sets a value of border chars
BorderColor Color Gets or sets a value of the grid border
Bounds Rect Gets the size and location of the control including its nonclient elements, in points, relative to the parent control
ColumnCount int Get of the column count
ColumnDefinitions GridColumnDefinitionCollection Gets a GridColumnDefinitionCollection defined on this instance of Grid
ContentCount int Gets the number of elements contained in the current control
DesiredSize Size Gets the size that this element computed during the measure pass of the layout process
DrawingContext IDrawingContext Gets a value of the drawing context
Foreground Color Gets or sets a brush that describes the text of a control
ForegroundIsTransparent bool Gets a value indicating whether the Foreground has Color.NotSet
Height int? Gets or sets the height of the control
Id long Gets a value of the control's identifier
IsMeasureValid bool Gets a value indicating whether component sizing was performed
IsVisualValid bool Gets a value indicating whether the component is being re-rendered
Location Point Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container
Margin Thickness Gets or sets the outer margin of an element
Padding Thickness Gets or sets a Thickness value that describes the amount of space between a control and its child element
Parent ContentControl Gets or sets the parent container of the control
RowCount int Get of the row count
RowDefinitions GridRowDefinitionCollection Gets a GridRowDefinitionCollection defined on this instance of Grid
ShowGridLine bool Gets or sets a value that indicates whether grid lines are visible within this Grid
Tag object Gets or sets the object that contains data about the control
Width int? Gets or sets the width of the control

Methods

Syntax Description
AddContent(Control content) Adds the specified control to the control collection
AddContent(Control content, int column, int row, int columnSpan, int rowSpan, HorizontalAlignment horizontal, VerticalAlignment vertical) Adds content to a table cell
Arrange(Rect) Positions child elements and determines a size for a Control. Parent elements call this method from their Arrange(Rect) implementation to form a recursive layout update
GetColumn(Control content) Get the column index of specified control
GetColumnSpan(Control content) Get the column span of specified control
GetHorizontalAlignment(Control content) Get the horizontal alignment of specified control
GetRow(Control content) Get the row of specified control
GetRowSpan(Control content) Get the row span of specified control
GetVerticalAlignment(Control content) Get the vertical alignment of specified control
InvalidateMeasure() Invalidates the measurement state (layout) for the element
InvalidateMeasureIfAutoSize() Invalidates the measurement state (layout) for the element if AutoSize property is true otherwise invalidates the rendering of the element
InvalidateVisual() Invalidates the rendering of the element, and forces a complete new layout pass. OnRender(IDrawingContext) is called after the layout cycle is completed
Measure(Size) Updates DesiredSize of a Control. Parent elements call this method from their own Measure(Size) implementations to form a recursive layout update
OnRender(IDrawingContext) Filling a pseudographics drawing context
ParentWindow() Gets the form the control is in
RemoveAllContent() Removes all items from the control collection
RemoveContent(Control content) Remove the specified control to the control collection
SetColumn(Control content, int column) Set column for specified control
SetColumnSpan(Control content, int columnSpan) Set column span for specified control
SetHorizontalAlignment(Control content, HorizontalAlignment horizontalAlignment) Set horizontal alignment for specified control
SetRow(Control content, int row) Set row for specified control
SetRowSpan(Control content, int rowSpan) Set row span for specified control
SetStyle(Action) Defines actions with an element style
SetVerticalAlignment(Control content, VerticalAlignment verticalAlignment) Set vertical alignment for specified control

Events

Event Description
OnAutoSizeChanged Occurs when the value of the AutoSize property changes
OnBackgroundChanged Occurs when the value of the Background property changes
OnBorderCharsChanged Occurs when the value of the BorderChars property changes
OnBorderColorChanged Occurs when the value of the BorderColor property changes
OnForegroundChanged Occurs when the value of the Foreground property changes
OnHeightChanged Occurs when the value of the Height property changes
OnMarginChanged Occurs when the value of the Margin property changes
OnPaddingChanged Occurs when the value of the Padding property changes
OnParentChanged Occurs when the value of the Parent property changes
OnShowGridLineChanged Occurs when the value of the ShowGridLine property changes
OnTagChanged Occurs when the value of the Tag property changes
OnWidthChanged Occurs when the value of the Width property changes
⚠️ **GitHub.com Fallback** ⚠️