article

Retrieving font and text metrics using C#

In several of my applications, I need to be able to line up text, be it blocks of text using different fonts, or text containers of differing heights. As far as I'm aware, there isn't a way of doing this natively in .NET, however with a little platform invoke we can get the information we need to do it ourselves as this short article demonstrates.

avatar
Richard Moss
article

Adding keyboard accelerators and visual cues to a WinForms control

Some weeks ago I was trying to make parts of WebCopy's UI a little bit simpler via the expedient of hiding some of the more advanced (and consequently less used) options. And to do this, I created a basic toggle panel control. This worked rather nicely, and while writing it I thought I'd write a short article on adding keyboard support to WinForm controls.

avatar
Richard Moss
article

Implementing events more efficiently in .NET applications

One of the things that frequently annoys me about third party controls (including those built into the .NET Framework) are properties that either aren't `virtual`, or don't have corresponding change events / virtual methods. Quite often I find myself wanting to perform an action when a property is changed, and if neither of those are present I end up having to create a custom version of the property, and as a rule, I don't like using the `new` keyword unless there is no other alternative. As a result of this, whenever I add properties to my WinForm controls, I tend to ensure they have a change event, and most often they are also virtual as I have a custom code snippet to build the boilerplate. That can mean some controls have an awful lot of events, many of which are rarely used. This article describes how you can explicitly implement events to reduce the amount of memory your types take.

avatar
Richard Moss
article

Generating code using T4 templates

Recently I was updating a library that contains two keyed collection classes. These collections aren't the usual run-of-the-mill collections as they need to be able to support duplicate keys. Normally I'd inherit from `KeyedCollection` but as with most collection implementations, duplicate keys are not permitted in this class. This article describes how I used T4 templates to dynamically generate my custom collection classes without requiring a public base class.

avatar
Richard Moss
article

Rotating an array using C#

I've recently been working on a number of small test programs for the different sections which make up a game I'm planning on writing. One of these test systems involved a series of polyominoes which I needed to rotate. Internally, the data for these shapes are stored as a simple boolean array, which I access as though it were two dimensions. This article and corresponding source code download describe how to rotate 2D rectangular arrays (or 1D arrays that masquerade as 2D) in 90° intervals clockwise or anti-clockwise.

avatar
Richard Moss
article

Writing Adobe Swatch Exchange (ase) files using C#

The second in a two part series showing how to write Adobe Stack Exchange (ase) files using C#

avatar
Richard Moss
article

Reading Adobe Swatch Exchange (ase) files using C#

The first of a two part series which describes how to load and save Adobe Swatch Exchange (ase) files using C#. This first article describes the file format, and provides a full example project that will read RGB based swatch files.

avatar
Richard Moss
article

Targeting multiple versions of the .NET Framework from the same project

The new exception management library I've been working on was originally targeted for .NET 4.6, changing to .NET 4.5.2 when I found that Azure websites don't support 4.6 yet. Regardless of 4.5 or 4.6, this meant trouble when I tried to integrate it with WebCopy - this product uses a mix of 3.5 and 4.0 targeted assemblies, meaning it couldn't actually reference the new library due the higher framework version. Rather than creating several different project files with the same source but different configuration settings, I decided that I would modify the library to target multiple framework versions from the same source project, and this article describes how I did this.

avatar
Richard Moss
article

Working around System.ArgumentException: Only TrueType fonts are supported. This is not a TrueType font

We recently created a a drop in replacement for the System.Windows.Forms.FontDialog component to avoid crashes when a user tries to select an invalid TrueType font.

avatar
Richard Moss
article

Sending SMS messages with Twilio

Last week I attended the NEBytes technology user group for the first time. One of the presentations was for Twilio, an easy to use platform for creating SMS and VoIP applications. This short article demonstrates (with a simple caveat) just how easy it is to use this platform for sending SMS messages - a perfect way of adding two factor authentication to your services, or sending alert notifications, or any number of use cases.

avatar
Richard Moss
article

Even more algorithms for dithering images using C#

Although I should really be working on adding the dithering algorithms into Gif Animator, I thought it would be useful to expand the repertoire of algorithms available for use with such tools. This article briefly mentions the expanded error diffusion algorithms that are now included, and in slightly more detail covers random dithering as well.

avatar
Richard Moss
article

Dithering an image using the Burkes algorithm in C#

Another article in my C# image dithering mini-series, this time covering the Burkes error diffusion algorithm.

avatar
Richard Moss