Set control position for Canvas : Canvas « Windows Presentation Foundation « VB.Net






Set control position for Canvas

Set control position for Canvas
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="250" Width="250" Loaded="Window_Loaded">
    <Canvas Name="canvas1">
    </Canvas>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes

Namespace WpfApplication1

  Public Partial Class Window1
    Inherits Window
    Private button1 As Button = Nothing
    Private button2 As Button = Nothing
    Private button3 As Button = Nothing

    Public Sub New()
      InitializeComponent()
    End Sub

    Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
      button1 = New Button() With { _
        .Content = "Button", _
        .Width = 70, _
        .Height = 23 _
      }
      Canvas.SetLeft(button1, 119)
      Canvas.SetTop(button1, 24)
      canvas1.Children.Add(button1)
      button2 = New Button() With { _
        .Content = "Wider" _
      }
      Canvas.SetLeft(button2, 44)
      Canvas.SetTop(button2, 69)
      canvas1.Children.Add(button2)
      button3 = New Button() With { _
        .Content = "Button" _
      }
      Canvas.SetLeft(button3, 78)
      Canvas.SetTop(button3, 119)
      button3.Padding = New Thickness(10, 2, 10, 2)
      canvas1.Children.Add(button3)
    End Sub
  End Class
End Namespace

   
    
    
    
    
  








Related examples in the same category

1.Align Button along with Canvas positionAlign Button along with Canvas position
2.Using a Canvas to absolutely position elementsUsing a Canvas to absolutely position elements
3.Simple CanvasSimple Canvas
4.StackPanel Demo and CanvasStackPanel Demo and Canvas
5.Canvas with MinHeight and MinWidthCanvas with MinHeight and MinWidth
6.Draws a Path element within a CanvasDraws a Path element within a Canvas
7.Draws several Line elements within a CanvasDraws several Line elements within a Canvas
8.Draws several Polyline elements within a CanvasDraws several Polyline elements within a Canvas
9.Rectangle with Fill and Canvas positionRectangle with Fill and Canvas position
10.Custom Coordinates by transforming the CanvasCustom Coordinates by transforming the Canvas
11.Draw path on a CanvasDraw path on a Canvas
12.Use Canvas coordinationUse Canvas coordination
13.Use Canvas to layout Buttons and LabelsUse Canvas to layout Buttons and Labels
14.Position UI Elements Using Exact CoordinatesPosition UI Elements Using Exact Coordinates
15.Pixel SnappedPixel Snapped
16.Positioning Rectangle on a CanvasPositioning Rectangle on a Canvas
17.Canvas inside canvas, showing relative absolute positioningCanvas inside canvas, showing relative absolute positioning
18.Aligning elements using multiple attached properties of CanvasAligning elements using multiple attached properties of Canvas
19.Layer elements in a Canvas elementLayer elements in a Canvas element
20.Use the four attached properties of the Canvas element: Bottom, Left, Right, and TopUse the four attached properties of the Canvas element: Bottom, Left, Right, and Top
21.Canvas PreviewMouseDown action and MouseDown actionCanvas PreviewMouseDown action and MouseDown action
22.Handles the MouseDown event on the CanvasHandles the MouseDown event on the Canvas
23.StatusBar inside a CanvasStatusBar inside a Canvas
24.Drag Items from a List and Drop Them on a CanvasDrag Items from a List and Drop Them on a Canvas
25.Print Visual(Canvas)Print Visual(Canvas)
26.Get position on a Canvas with Canvas.GetLeftGet position on a Canvas with Canvas.GetLeft
27.Use a Thumb to resize a Canvas control by responding to the DragDelta event.Use a Thumb to resize a Canvas control by responding to the DragDelta event.
28.Canvas Positioning Properties SampleCanvas Positioning Properties Sample
29.Canvas.SetTopCanvas.SetTop
30.Canvas.SetBottomCanvas.SetBottom
31.Canvas.SetRightCanvas.SetRight
32.Add buttons to a Canvas with codeAdd buttons to a Canvas with code