Programmatically use the positioning methods of Grid : Grid « Windows Presentation Foundation « VB.Net






Programmatically use the positioning methods of Grid

Programmatically use the positioning methods of Grid
      

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="grid_getset_methods.Window1"
    Title="Grid Methods Sample">
    <DockPanel VerticalAlignment="Top" HorizontalAlignment="Left">
        <Grid Margin="10" DockPanel.Dock="Left">
          <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition/>
          </Grid.RowDefinitions>
          <StackPanel Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Orientation="Vertical">
            <Button Click="setCol0">Move Rectangle to Column 0</Button>
            <Button Click="setCol1">Move Rectangle to Column 1</Button>
            <Button Click="setCol2">Move Rectangle to Column 2</Button>
            <Button Click="setRow0">Move Rectangle to Row 0</Button>
            <Button Click="setRow1">Move Rectangle to Row 1</Button>
            <Button Click="setRow2">Move Rectangle to Row 2</Button>
            <Button Click="setColspan">Span All Columns</Button>
            <Button Click="setRowspan">Span All Rows</Button>
          </StackPanel>
        </Grid>
      <Grid DockPanel.Dock="Top" Name="grid1" ShowGridLines="True" Width="400" Height="400">
        <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
      </Grid.RowDefinitions>
        <Rectangle Name="rect1" Fill="Silver" Grid.Column="0" Grid.Row="0"/>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="0" Grid.Row="0" Margin="5">Column 0, Row 0</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="1" Grid.Row="0" Margin="5">Column 1, Row 0</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="2" Grid.Row="0" Margin="5">Column 2, Row 0</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="0" Grid.Row="1" Margin="5">Column 0, Row 1</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="1" Grid.Row="1" Margin="5">Column 1, Row 1</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="2" Grid.Row="1" Margin="5">Column 2, Row 1</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="0" Grid.Row="2" Margin="5">Column 0, Row 2</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="1" Grid.Row="2" Margin="5">Column 1, Row 2</TextBlock>
        <TextBlock FontSize="15" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="2" Grid.Row="2" Margin="5">Column 2, Row 2</TextBlock>
      </Grid>
    </DockPanel>
</Window>
//File:Window.xaml.vb


Imports System
Imports System.Windows
Imports System.Windows.Controls

Namespace grid_getset_methods
  Public Partial Class Window1
    Inherits Window
    Private Sub setCol0(sender As Object, e As RoutedEventArgs)
      Grid.SetColumn(rect1, 0)
      Console.WriteLine("Column " & Grid.GetColumn(rect1).ToString())

    End Sub
    Private Sub setCol1(sender As Object, e As RoutedEventArgs)
      Grid.SetColumn(rect1, 1)
      Console.WriteLine("Column " & Grid.GetColumn(rect1).ToString())
    End Sub
    Private Sub setCol2(sender As Object, e As RoutedEventArgs)
      Grid.SetColumn(rect1, 2)
      Console.WriteLine("Column " & Grid.GetColumn(rect1).ToString())
    End Sub
    Private Sub setRow0(sender As Object, e As RoutedEventArgs)
      Grid.SetRow(rect1, 0)
      Console.WriteLine("Row " & Grid.GetRow(rect1).ToString())
    End Sub
    Private Sub setRow1(sender As Object, e As RoutedEventArgs)
      Grid.SetRow(rect1, 1)
      Console.WriteLine("Row " & Grid.GetRow(rect1).ToString())
    End Sub
    Private Sub setRow2(sender As Object, e As RoutedEventArgs)
      Grid.SetRow(rect1, 2)
      Console.WriteLine("Row " & Grid.GetRow(rect1).ToString())
    End Sub
    Private Sub setColspan(sender As Object, e As RoutedEventArgs)
      Grid.SetColumnSpan(rect1, 3)
      Console.WriteLine("ColumnSpan " & Grid.GetColumnSpan(rect1).ToString())
    End Sub
    Private Sub setRowspan(sender As Object, e As RoutedEventArgs)
      Grid.SetRowSpan(rect1, 3)
      Console.WriteLine("RowSpan " & Grid.GetRowSpan(rect1).ToString())
    End Sub
    Private Sub clearAll(sender As Object, e As RoutedEventArgs)
      Grid.SetColumn(rect1, 0)
      Grid.SetRow(rect1, 0)
      Grid.SetColumnSpan(rect1, 1)
      Grid.SetRowSpan(rect1, 1)
    End Sub
  End Class
End Namespace

   
    
    
    
    
    
  








Related examples in the same category

1.The first row of a gridThe first row of a grid
2.Positioning elements using a Grid
3.Layout within a button using GridLayout within a button using Grid
4.Label in a GridLabel in a Grid
5.Display Content in Resizable Split PanelDisplay Content in Resizable Split Panel
6.Place more than two object to one cellPlace more than two object to one cell
7.Add StackPanel to Row 0Add StackPanel to Row 0
8.Using the attached properties of Grid
9.Two columns and three rows columnsTwo columns and three rows columns
10.Fixed column widthFixed column width
11.Grid with row and column definition and place buttons to grid cellsGrid with row and column definition and place buttons to grid cells
12.Shared Size GroupsShared Size Groups
13.DoubleSplit WindowDoubleSplit Window
14.Grid PreviewMouseDown action and MouseDown actionGrid PreviewMouseDown action and MouseDown action
15.Grid MouseMoveGrid MouseMove
16.Grid MouseLeftButtonDownGrid MouseLeftButtonDown
17.Grid MouseLeftButtonUpGrid MouseLeftButtonUp
18.Use the Grid to create a dialog box that uses the WPF layout API
19.Is Grid ReadOnlyIs Grid ReadOnly
20.Dynamically add Button to a Grid and add Action listenerDynamically add Button to a Grid and add Action listener
21.Setting Grid row heights in codeSetting Grid row heights in code
22.Layout Controls with Grid in codeLayout Controls with Grid in code
23.Show Grid lines in codeShow Grid lines in code
24.Grid mouse down eventGrid mouse down event
25.Grid Preview mouse down eventGrid Preview mouse down event
26.Put Button onto a GridPut Button onto a Grid
27.Use the IsSharedSizeScope attached property of the Grid elementUse the IsSharedSizeScope attached property of the Grid element
28.Change the margins of an element that is within a Grid by XAML and programmatic codeChange the margins of an element that is within a Grid by XAML and programmatic code
29.Add a ColumnDefinition to GridAdd a ColumnDefinition to Grid
30.Add a RowDefinition to GridAdd a RowDefinition to Grid
31.Clear All ColumnsClear All Columns
32.Clear All RowsClear All Rows
33.Remove One ColumnRemove One Column
34.Remove One RowRemove One Row
35.The current number of ColumnsThe current number of Columns
36.The current number of RowsThe current number of Rows
37.Remove 5 Columns with ColumnDefinitions.RemoveRangeRemove 5 Columns with ColumnDefinitions.RemoveRange
38.Remove 5 Row with RowDefinitions.RemoveRange
39.Contains RowContains Row
40.Contains Column?Contains Column?
41.Insert RowInsert Row
42.Insert ColumnInsert Column
43.Set control to specific row and column in codeSet control to specific row and column in code
44.The default GroupStyle indents the items in a groupThe default GroupStyle indents the items in a group
45.A resizable layoutbased on GridA resizable layoutbased on Grid