This tutorial aims to provide you with the basics of Windows Forms and Windows Presentation Foundation (WPF). After going through this tutorial, you should be able to create simple applications using these two frameworks.
Windows Forms is a graphical user interface application programming interface (API) included in Microsoft's .NET Framework. It provides a platform for developing rich client applications for desktop computers.
// Create a new Windows Form Application
// In Visual Studio, go to File > New > Project > Windows Forms App (.NET Framework)
Windows Presentation Foundation (WPF) is a UI framework that creates desktop client applications. It provides a consistent programming model for building applications and provides a clear separation between the UI and the business logic.
// Create a new WPF Application
// In Visual Studio, go to File > New > Project > WPF App (.NET Framework)
// Include the necessary libraries
using System;
using System.Windows.Forms;
public class HelloWorld : Form
{
static void Main()
{
// Create a new instance of the form
HelloWorld hw = new HelloWorld();
// Run the form
Application.Run(hw);
}
public HelloWorld()
{
// Set the text property
this.Text = "Hello, World!";
}
}
The above code creates a new Windows Form application with the title "Hello, World!".
<Window x:Class="HelloWorld.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hello, World!" Height="350" Width="525">
<Grid>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
Hello, World!
</TextBlock>
</Grid>
</Window>
The above code creates a new WPF application with the title "Hello, World!" and displays the text "Hello, World!" in the center of the window.
In this tutorial, we introduced you to the basics of Windows Forms and WPF and demonstrated how to create simple applications using these frameworks.
Create a Windows Form application that displays a button. When the user clicks the button, display a message box that says "You clicked the button!".
Create a WPF application that displays a text box and a button. When the user enters text in the text box and clicks the button, display a message box that includes the text entered by the user.
Modify the WPF application from exercise 2 to use data binding to display the text entered by the user in a label instead of a message box.