Use the Grid to create a dialog box that uses the WPF layout API : Grid « Windows Presentation Foundation « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » GridScreenshots 
Use the Grid to create a dialog box that uses the WPF layout API
      

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Grid_Run_Dialog.Window1"
    Name="mainWindow" Loaded="onLoaded" Width="425" Height="200"/>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media

Namespace Grid_Run_Dialog
  Public Partial Class Window1
    Inherits Window
    Private grid1 As New Grid()
    Private colDef1 As New ColumnDefinition()
    Private colDef2 As New ColumnDefinition()
    Private colDef3 As New ColumnDefinition()
    Private colDef4 As New ColumnDefinition()
    Private colDef5 As New ColumnDefinition()
    Private rowDef1 As New RowDefinition()
    Private rowDef2 As New RowDefinition()
    Private rowDef3 As New RowDefinition()
    Private rowDef4 As New RowDefinition()
    Private txt1 As New TextBlock()
    Private txt2 As New TextBlock()
    Private button1 As New Button()
    Private button2 As New Button()
    Private button3 As New Button()
    Private tb1 As TextBox
    Private img1 As New Image()

    Private Sub onLoaded(sender As Object, e As EventArgs)
      grid1.Background = Brushes.Gainsboro
      grid1.HorizontalAlignment = HorizontalAlignment.Left
      grid1.VerticalAlignment = VerticalAlignment.Top
      grid1.ShowGridLines = True
      grid1.Width = 425
      grid1.Height = 165

      colDef1.Width = New GridLength(1, GridUnitType.Auto)
      colDef2.Width = New GridLength(1, GridUnitType.Star)
      colDef3.Width = New GridLength(1, GridUnitType.Star)
      colDef4.Width = New GridLength(1, GridUnitType.Star)
      colDef5.Width = New GridLength(1, GridUnitType.Star)
      grid1.ColumnDefinitions.Add(colDef1)
      grid1.ColumnDefinitions.Add(colDef2)
      grid1.ColumnDefinitions.Add(colDef3)
      grid1.ColumnDefinitions.Add(colDef4)
      grid1.ColumnDefinitions.Add(colDef5)

      rowDef1.Height = New GridLength(1, GridUnitType.Auto)
      rowDef2.Height = New GridLength(1, GridUnitType.Auto)
      rowDef3.Height = New GridLength(1, GridUnitType.Star)
      rowDef4.Height = New GridLength(1, GridUnitType.Auto)
      grid1.RowDefinitions.Add(rowDef1)
      grid1.RowDefinitions.Add(rowDef2)
      grid1.RowDefinitions.Add(rowDef3)
      grid1.RowDefinitions.Add(rowDef4)

      img1.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("fil:///c:/image.png", UriKind.Relative))
      Grid.SetRow(img1, 0)
      Grid.SetColumn(img1, 0)

      txt1.Text = "Text"
      txt1.TextWrapping = TextWrapping.Wrap
      Grid.SetColumnSpan(txt1, 4)
      Grid.SetRow(txt1, 0)
      Grid.SetColumn(txt1, 1)

      txt2.Text = "Open:"
      Grid.SetRow(txt2, 1)
      Grid.SetColumn(txt2, 0)

      Grid.SetRow(tb1, 1)
      Grid.SetColumn(tb1, 1)
      Grid.SetColumnSpan(tb1, 5)

      button1.Content = "OK"
      button2.Content = "Cancel"
      button3.Content = "Browse ..."
      Grid.SetRow(button1, 3)
      Grid.SetColumn(button1, 2)
      button1.Margin = New Thickness(1001015)
      button2.Margin = New Thickness(1001015)
      button3.Margin = New Thickness(1001015)
      Grid.SetRow(button2, 3)
      Grid.SetColumn(button2, 3)
      Grid.SetRow(button3, 3)
      Grid.SetColumn(button3, 4)

      grid1.Children.Add(img1)
      grid1.Children.Add(txt1)
      grid1.Children.Add(txt2)
      grid1.Children.Add(tb1)
      grid1.Children.Add(button1)
      grid1.Children.Add(button2)
      grid1.Children.Add(button3)

      mainWindow.Content = grid1

    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.Is Grid ReadOnlyIs Grid ReadOnly
19.Dynamically add Button to a Grid and add Action listenerDynamically add Button to a Grid and add Action listener
20.Setting Grid row heights in codeSetting Grid row heights in code
21.Layout Controls with Grid in codeLayout Controls with Grid in code
22.Show Grid lines in codeShow Grid lines in code
23.Grid mouse down eventGrid mouse down event
24.Grid Preview mouse down eventGrid Preview mouse down event
25.Put Button onto a GridPut Button onto a Grid
26.Use the IsSharedSizeScope attached property of the Grid elementUse the IsSharedSizeScope attached property of the Grid element
27.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
28.Programmatically use the positioning methods of GridProgrammatically use the positioning methods of Grid
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.