Visual Studio 2019 (WPF VB.Net Source Code & XAML) Using the Grid Layout and Button Controls


Visual Studio 2019 (WPF VB.Net Source Code & XAML) Using the Grid Layout and Button Controls.

🎓 Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS).
ðŸ“ē Enroll Now: https://bit.ly/2WcbRhX

In this video tutorial you will learn: 
➜ How to use the Grid Layout and Button Controls.
➜ How to Add an Event Handler Using Code.
➜ How to Add a Button Click Event Handler in WPF (Attach single click event handler with multiple buttons).

🚀 For Visual C#, see: https://youtu.be/YkhkW-Bf0zg

[Screenshot]


[YouTube]

[XAML & VB.NET Code Behind]
Short link: http://bit.ly/2E08geD

MainWindow.xaml

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="WPF (VB.NET) : Button and Grid Example : Code A Minute : iBasskung Tutorial" 
        Height="570" Width="750"
        Background="CornflowerBlue"
        WindowStartupLocation="CenterScreen">
    
    <!-- 2 Columns and 3 Rows -->
    
    <Grid ShowGridLines="True" Margin="10">
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <Button Name="firstRowButton1"
                Grid.Column="0"
                Grid.ColumnSpan="2"
                Grid.Row="0"
                Content="(:  My Button 1  :)"
                FontSize="52"
                FontWeight="Bold"
                FontStyle="Oblique"
                Height="155"
                Width="705"
                Background="Crimson"
                Foreground="White"
                HorizontalAlignment="Stretch"
                HorizontalContentAlignment="Center"
                VerticalAlignment="Center"
                VerticalContentAlignment="Center"
                BorderBrush="White"
                BorderThickness="5"
                Margin="0"
                Padding="0"
                Click="FirstRowButton1_Click"/>

        <Button Name="secondRowButton1"
                Grid.Column="0"
                Grid.ColumnSpan="1"
                Grid.Row="1"
                Content="Button 2"
                FontSize="52"
                FontWeight="Bold"
                FontStyle="Normal"
                Height="150"
                Width="330"
                Background="MediumVioletRed"
                Foreground="White"
                HorizontalAlignment="Left"
                HorizontalContentAlignment="Left"
                VerticalAlignment="Top"
                VerticalContentAlignment="Top"
                BorderBrush="Yellow"
                BorderThickness="5"
                Margin="5,10,0,0"
                Padding="12,0,0,0"
                Click="ButtonEventHandler_Click"/>

        <Button Name="secondRowButton2"
                Grid.Column="1"
                Grid.ColumnSpan="1"
                Grid.Row="1"
                Content="Button 3"
                FontSize="52"
                FontWeight="Bold"
                FontStyle="Normal"
                Height="150"
                Width="330"
                Background="MediumVioletRed"
                Foreground="White"
                HorizontalAlignment="Right"
                HorizontalContentAlignment="Right"
                VerticalAlignment="Top"
                VerticalContentAlignment="Top"
                BorderBrush="Yellow"
                BorderThickness="5"
                Margin="0,10,5,0"
                Padding="0,0,12,0"
                Click="ButtonEventHandler_Click"/>

        <Button Name="thirdRowButton1"
                Grid.Column="0"
                Grid.ColumnSpan="1"
                Grid.Row="2"
                Content="Button 4"
                FontSize="52"
                FontWeight="Bold"
                FontStyle="Normal"
                Height="150"
                Width="330"
                Background="DarkCyan"
                Foreground="Gold"
                HorizontalAlignment="Left"
                HorizontalContentAlignment="Left"
                VerticalAlignment="Bottom"
                VerticalContentAlignment="Bottom"
                BorderBrush="Yellow"
                BorderThickness="5"
                Margin="5,0,0,5"
                Padding="12,0,0,0"
                Click="ButtonEventHandler_Click"/>

        <Button Name="thirdRowButton2"
                Grid.Column="1"
                Grid.ColumnSpan="1"
                Grid.Row="2"
                Content="Button 5"
                FontSize="52"
                FontWeight="Bold"
                FontStyle="Normal"
                Height="150"
                Width="330"
                Background="DarkCyan"
                Foreground="Gold"
                HorizontalAlignment="Right"
                HorizontalContentAlignment="Right"
                VerticalAlignment="Bottom"
                VerticalContentAlignment="Bottom"
                BorderBrush="Yellow"
                BorderThickness="5"
                Margin="0,0,5,5"
                Padding="0,0,12,0"
                Click="ButtonEventHandler_Click"/>

    </Grid>
    
</Window>

=================

MainWindow.xaml.vb

Option Explicit On
Option Strict On

Class MainWindow

    Private Sub FirstRowButton1_Click(sender As Object, e As RoutedEventArgs)
        ' Ex.1
        Dim btn As Button = CType(sender, Button)
        MessageBox.Show("You pressed:" & Environment.NewLine &
                        "Button Name: " & btn.Name & Environment.NewLine &
                        "Button Text: " & btn.Content.ToString(), "WPF (VB.Net) : Button & Grid Example", MessageBoxButton.OK, MessageBoxImage.Information)
    End Sub

    Private Sub ButtonEventHandler_Click(sender As Object, e As RoutedEventArgs)
        ' Ex.2
        Dim btn As Button = CType(sender, Button)
        MessageBox.Show("You pressed:" & Environment.NewLine &
                        "Button Name: " & btn.Name & Environment.NewLine &
                        "Button Text: " & btn.Content.ToString(), "WPF (VB.Net) : Button & Grid Example", MessageBoxButton.OK, MessageBoxImage.Information)
    End Sub

End Class

Comments