Windows

How I Setup WSL In Windows 10 With the Windows Terminal App

I’ve had a long history of not being a fan of the Windows operating system. While Windows 7 was a decent release of the OS, version eight was an absolute dumpster fire and the early builds of Windows 10 weren’t much better. The more recent builds of Windows 10, however, have certainly started to win me over, especially when Microsoft surprised everyone by coming out with the Windows Subsystem for Linux.

The default setup for WSL is anything but perfect but it’s possible to get a really nice looking, highly functional setup with just a little bit of work. Let’s take a look at how I have everything set up.

Continue reading…

Creating an OpenCV 4 Project in Visual Studio 2017 & 2019

In my previous tutorial, I outlined how to build the OpenCV 4 library on Microsoft Windows 10. In that tutorial, however, I did not mention how to use that library in an actual project. This time around I will be showing you how to create an OpenCV 4 project within Microsoft Visual Studio 2017.

Please note that I am going to assume that your OpenCV install is set up in the way I outlined in my previous tutorial. That is to say that the necessary files are located within an OpenCV folder in your C:\ drive. If this is not the case you’ll have to make some minor modifications to the steps outlined here to suit your setup.

Let’s get started!

Continue reading…

Installing OpenCV 4 on Windows 10

I love working with the OpenCV library, but it can be a royal pain in the butt to get it installed and running on your machine. This is especially true for Microsoft Windows. Despite a Google search turning up plenty of results for articles promising to show you how to do it, they all seem to have issues or be incomplete. This results in a rather frustrating experience when you just want to get things up and running.

The purpose of this tutorial is to walk you through, step-by-step, how to install OpenCV version 4 on your Microsoft Windows 10 system. So, let’s quit talking about it and jump right in!

Continue reading…

Easily Detect Changes to All Text Boxes in Windows Form [C#]

There are a number of instances in which we might want to detect when there have been changes to text boxes within a C# Windows Forms app. As an example, I’m working on building a quick application for managing a database of natural sandstone arches within the state of Kentucky. My (very rough-draft) app has the following screen to add an arch to the database:

I want to have a way to detect if there have been changes within any of the text boxes when I hit the cancel button. This way, I can display a confirmation dialog to the user.

One way I could go about this is by individually setting the TextChanged callback for each and every textbox. This would certainly work, but it would lead to a lot of code duplication and things would get messy quite quickly. A better way would be to programmatically set the callback for each text box. This is actually really easy to do!

Step 1: Override the Form’s OnLoad Method

The first thing we need to do is override our form’s OnLoad method. This can be done quite simply:

override protected void OnLoad(EventArgs e)
{

}

Step 2: Programmatically Set TextChanged Callback for All Text Boxes

The next step is to set the TextChanged callback for all our text boxes. We can do this by adding the following to our OnLoad method:

override protected void OnLoad(EventArgs e)
{
	foreach (Control control in this.Controls)
	{
		if (control.GetType() == typeof(TextBox))
		{
			(control as TextBox).TextChanged += Form_TextChanged;
		}
	}
}

All we are doing here is iterating over all the controls in our form. If the control is of the type TextBox, then we set the TextChanged callback to be the Form_TextChanged callback.

Step 3: Build the Callback Function

Now that we have specified a callback for the TextChanged event, we need to actually build the callback function. In this case, I’m going to keep things simple and simply set the value of a boolean property to true if a text change has been detected:

private void Form_TextChanged(object sender, EventArgs e)
{
	this.hasUnsavedChanges = true;
}

Now I can use this boolean property anywhere I want to test for unsaved changes (in my case, when the cancel button is clicked).