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

  1. 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.

    Windows Forms

  2. Specify a project name confirm with Next.

  3. Select your preferred Framework version such as .NET 8 (Long-term support) and confirm with Create.

Adding the Control

  1. Select the project in the Solution Explorer and click Project -> Manage NuGet Packages... from the main menu.

  2. Select Text Control Offline Packages as the Package source and click Browse.

  3. Select TXTextControl.TextControl.WinForms.SDK and click Install.

    Windows Forms

  4. In the Solution Explorer, open the form Form1 and find the TX Text Control 32.0 tab in the Toolbox.

    Windows Forms

  5. 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.

Getting Started with Windows Forms (.NET 5 and better)

Adding the Packaging Project

  1. Right-click the solution in the Solution Explorer and select Add -> New Project....

  2. Select Windows Application Packaging Project and confirm with Next.

    Windows Forms

  3. 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.

    Windows Forms

  4. 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.

  5. Right-click the packaging project in the Solution Explorer and select Set as Startup Project.

Configuring the Packaging Project

  1. Expand the Applications node of the packaging application in the Solution Explorer and select your application that uses TX Text Control.

    Windows Forms

  2. Open the Properties window and set the Trust Level to Partial Trust.

    Windows Forms

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.

  1. Open the Package.appxmanifest file in the packaging project.

  2. Click the Capabilities tab and enable the required capabilities. As an example, we will enable microphone access in this tutorial.

    Windows Forms

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.