WinForms – Loop through a form’s controls

Forms also have a collection of controls (Controls property) that you can loop through. This is useful for when you want to do something to multiple controls and don’t want to have to manually type out code to deal with individual controls. Here’s an example of looping through a form’s top-level controls: Note: In the … Read more

WinForms – Bind controls to an object data source

Mapping classes to WinForm controls manually is probably the most tedious thing you can do in coding. In order to minimize this coding effort, you can bind your controls to an object data source. In this article, I’ll show how to do this in a WinForms App (.NET Core+) project. First, I’ll show step-by-step how … Read more

C# – How to switch on type

Sometimes you may find it necessary to have conditional logic based on an object’s type. The simplest way to do this is to switch on the type, like this: This feature is called type pattern matching. Before this feature was added (in C# 7), you’d have to use a bunch of if-else’s and check the … Read more