Posts

Showing posts with the label Windows Forms

Quick fix for 'Unrecognized configuration section system.diagnostics' error in .NET apps

.NET can be used to create a variety of different types of app, coming with various technologies such as WPF and Windows Forms to help you create them. .NET apps support providing a .config file with the app that can be used to store various bits of configuration information about the app. There is an issue, however, that you might encounter when adding this file to your project (either manually or automatically, such as when you create a .settings file). The issue is that this file can cause a System.Configuration.ConfigurationErrorsException exception, with an error message that starts with something like 'Unrecognized configuration section system.diagnostics'. Luckily, there is an easy fix for this issue which simply involves adding a single line of code to your config file. The Fix So, to fix the issue, first open your project's configuration file (it will probably be named app.config or something like that) and add the following line under <configSections>: < ...

How to check if your Windows packaged app was launched from a StartupTask in C# and VB

Image
Apps running on startup is very common in Windows these days; many apps do this in order to run in the background to provide services such as notifications or a tray/taskbar corner icon. Windows has multiple avenues apps can use to run on startup however, the concept is usually the same - apps can specify an executable to run on startup along with arguments either for all users or the current user and the executable will run when the user signs in. One of these avenues is the StartupTask feature of UWP/MISX packages. You can simply specify these in your app's manifest and your app will be able to run when the current user signs in. As a developer, you might want to write code to check if your app was launched by a startup task - this might be useful if, for example, you want your app to run in the background and not show a main window if it is launched automatically from a StartupTask. How to check if app was launched from a StartupTask The first thing we'll need to do is make ...

How to allow picking files from other apps in a file picker in WPF and Windows Forms/WinForms in C# and VB

Image
You may have noticed that sometimes in file pickers in Windows, you not only have the option of picking files from folders, but also have the option of picking files through other apps - like selecting a photo from your photos library using the Photos app or taking a picture with the Camera app, all right from the file picker. What you may have noticed, however, is that the options to pick from apps don't always show up. For context, here is a file picker that lets you pick from other apps: ...and here is one without the options to pick from other apps: As you can see, in the second screenshot, the options to pick files using the Camera or Photos app are gone. As a developer, you might want to show those options as they can be useful - for example, the Photos app compiles all your photos together, making it easy to look through them all instead of having to dig through folders and the Camera app can be used to allow users to take photos with the camera right from your Windows Fo...