Because Windows applications have always lacked a security concept baked into Windows, the move to .NET provides Windows Forms and WPF applications with the ability to run in secured AppContainers. By default, Windows Forms applications have full access to system resources such as camera, microphone, location, and user-specific data.
Now, when applications are run in AppContainers, they are isolated and have limited access to resources, except when they are being requested.
MSIX is a Windows application packaging format that provides a modern way to package all of your Windows applications.
This tutorial shows how to create a Windows Forms application using TX Text Control and run it in an AppContainer.
Creating the Project
-
Open Visual Studio 2022 and create a new project. Select C# or Visual Basic from the Languages drop-down list, Windows from the Platform list and Desktop as the Project Type. Find the project template Windows Forms App and confirm with Next.
-
Specify a project name confirm with Next.
-
Select your preferred Framework version such as .NET 8 (Long-term support) and confirm with Create.
Adding the Control
-
Select the project in the Solution Explorer and click Project -> Manage NuGet Packages... from the main menu.
-
Select Text Control Offline Packages as the Package source and click Browse.
-
Select TXTextControl.TextControl.WinForms.SDK and click Install.
-
In the Solution Explorer, open the form Form1 and find the TX Text Control 32.0 tab in the Toolbox.
-
Select the icon TextControl and draw it onto the opened form.
Learn More
If you want to learn how to add the other components, such as a ribbon, take a look at this article.
Adding the Packaging Project
-
Right-click the solution in the Solution Explorer and select Add -> New Project....
-
Select Windows Application Packaging Project and confirm with Next.
-
Specify a project name and confirm with Create.
Select Windows 10, version 1809 (10.0; Build 17763) as the minimum version and confirm with OK.
-
Right-click the packaging project in the Solution Explorer and select Add -> Project Reference....
Check the Windows Forms project you created earlier and confirm with OK.
-
Right-click the packaging project in the Solution Explorer and select Set as Startup Project.
Configuring the Packaging Project
-
Expand the Applications node of the packaging application in the Solution Explorer and select your application that uses TX Text Control.
-
Open the Properties window and set the Trust Level to Partial Trust.
When you run the application now, it runs in a secure application container.
Configuring Resources
To give the application access to specific resources, you must manipulate the Package.appxmanifest file.
-
Open the Package.appxmanifest file in the packaging project.
-
Click the Capabilities tab and enable the required capabilities. As an example, we will enable microphone access in this tutorial.
When you run the application now, it runs in a secure application container and has access to the microphone.
Conclusion
MSIX is a Windows application packaging format that provides a modern way to package all of your Windows applications. This tutorial showed how to create a Windows Forms application using TX Text Control and run it in an AppContainer.