WPF學習日誌 ~ Canvas ~

WPF學習日誌 ~ Canvas ~

之前我們有介紹WPF裡面的容器,這個是最後一個容器了,Canvas,它的主要特性其實就是

利用絕對位置來排列控制項,下面我們用簡單的測試程式碼來看一下

 

Class Window1
    Dim cv As Canvas
 
    Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        cv = New Canvas
        cv.Width = 300
        cv.Height = 300
        cv.Background = Brushes.AliceBlue
        For i As Integer = 0 To 4
            Dim B As New Button
            B.Content = "_" & i.ToString
            Canvas.SetLeft(B, i * 20)
            Canvas.SetTop(B, i * 20)
            cv.Children.Add(B)
        Next
        Me.Content = cv
    End Sub
End Class