Introduction
In this article, I will explain how to create popup notifications in a Windows Forms app using Visual Studio 2017.
Windows Forms desktop alert component is used to display a popup window and implement notifications to users about a particular event that has occurred. It is easy to integrate the desktop alert control in a WinForms app and customize it based on your needs using C# API.
To add a control to a WinForms app, you can simply drag and drop it from Toolbox to a Form.
Step 1. Create a Project
Create a new Windows Forms app in Visual Studio 2017.
New Project -> Visual C# -> Windows Forms App (.NET Framework). See below.
Step 2. Designer Page
By default your Form should be opened in the designer. If not, double-click on the Form1.cs.
Now, let's add a button control to the form by dragging a Button control from the Toolbox to the form. You may also want to change the properties of the button.
Step 3. Install Nuget Packages
Download and install Tulpep.NotificationWindow is used to implement popup notifications in the app.
Step 4. Coding
To add an alert window to the Form, create a handler for the Button Click event by simply double-clicking on the button. Now, copy and paste the following C# code snippet to the button click event handler. This code creates a PopupNotifier, sets its title and text, and opens the popup. You can change the content the way you like.
private void button1_Click(object sender, EventArgs e)
{
PopupNotifier popup = new PopupNotifier();
popup.TitleText = "BE HAPPY";
popup.ContentText = "Thank you";
popup.Popup(); // show
}
Step 5. Run and test
Now, simply run the app and click on the Show button. You will notice a popup is opened at the right bottom of your Windows screen.
You can also customize the way your notification window looks by setting its properties.
Step 6. Additional design
You can also add an image to the popup notification.
To display an image along with the text in the popup notification, add an Image as a resource to the app and set the Image property of the control.
The code snippet sets the Image property of the control. You can also create an Image at run time by using the Image class if you like to use an external file.
Summary
A WinForms app can implement desktop notifications by using the PopupNotifier control. In this basic article, we saw how to use the control to implement a Windows notification and set its properties.