Thursday, 4 May 2017

Creating a Sample WPF Application in Visual Studio 2015 using Visual Basic WPF

What is WPF(Windows Presentation Foundation) application?

It is a graphical subsystem in windows to render user interface in windows-based applications. WPF works on the base of DirectX which is a set of API's.  


1.Open visual studio 2015 and create a new WPF application with the name Hello:



2.Create two radio buttons:

         To create radio button double click on Radio Button control in toolbox. If the toolbox is hidden, select view menu and click on toolbox (or) use a shortcut "Ctrl+Alt+X".  You can create a radio button on double clicking on radio button which is listed in "Common Wpf Controls".



3.Again create another radio button. And place them by dragging. After dragging and placing both the radio buttons the main window will appear like this.



4.The names behind the radio buttons is "RadioButton" by default. The name of the button can be changed as per our requirement of its use in the application. To change the name of radiobutton select the radiobutton to access the properties of it. And then edit the name in "Content Property" as shown in the figure below.




5.Select each radio button and change the font size and its style as shown in the figure below.



6.Then add a button into the main window by double clicking on the "Button" in the toolbox window. And then change its name is "Display". Adjust the size of the button to look apt to the window size.



7.Double click on the "Display Button" to write the code. The code is about to generate a message box when you click the button in the main window. The message box display different messages based on the selection of hello and goodbye radio buttons. The code is as follows:


Class MainWindow
    Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
        If radioButton.IsChecked = True Then
            MessageBox.Show("Hello")
        Else radiobutton.IsChecked = True
            MessageBox.Show("GoodBye")
        End If
    End Sub
End Class



Then click debug to run the application. 



No comments :

Post a comment