Cloister's C# Samples and Articles

Here you will find random sample programs and I've written in C#, as .zip source code bundles, precompiled binaries, and in some cases, actual .MSI installers. As well, here you will find the HHHH Custom Control library (woo!), containing all of my custom controls that are fit for public consumption, as well as any others that other people submit to me.

All of these samples are designed and tested on Windows XP SP2 only. Whether they work at all on other flavors of Windows is anybody's guess. After the samples, you will find articles I have written to cover some gaps in the otherwise excellent documentation collection that comes with Visual Studio.

Obligatory Disclaimer and Statement of Rights Retained:

These samples are provided, "as is", with no warranty expressed or implied of fitness for any purpose. Permission is expressly granted to anyone to download these samples for the following purposes:

Unless specific arrangements have been made between you and me, permission is expressly withheld from everyone to download these samples for all of the following purposes. This list augments, but does not supercede, any rights explicitly listed in separate license agreements contained within any of the samples themselves:

I retain any additional rights not explicitly listed here. But enough of this legalistic garbage. On with the samples!

Samples

NameDescriptionSourceBinaryDate
Epitome My first non-trivial WinForms App, written as an exploration into the concept of Image Epitomes. Being my first app, you'll be able to see that I had a lot to learn about control layout, resizing, etc. Under the covers the application is multithreaded (you really can't write an interesting WinForms app that isn't), Has a fairly clean separation between the UI and the data being manipulated, and supports loading and saving of datasets. Of course, if you read the paper on Image Epitomes, and look at my code, you'll see that my implementation in no real way matches the math that the researchers describe, and in fact, my epitomes sort of suck. Maybe someday I'll learn more math and fix this... Visual Studio Project Not Available 2/7/2005
Filter Lab A silly little image processing program that allows you to view images through any of a number of filters (Hue, saturation, R, G, B, etc.) Interesting features include multithreading (filters run in their own threads), support for a progress meter for long-running filters, and complete separation between the UI code and the filter code. The UI uses information exposed by each filter to dynamically create menu commands and parameter-input dialog boxes, so that you can add new filters to the application without modifying the UI (either through code or through the designer) at all.
Update: A friend of mine sent me some convolution matrix code, which I adapted into FilterLab. The ConvMatrix class is essentially his (with some interface tweaks on my part), as are the functions for creating Sobol X- and Y-edge detection matrices, but the ApplyConvMatrix() implementation is mine.
Update 2: This week I implemented a buffer optimization on some of the filters, based on an idea in my friend's convolution matrix code, that speeds the affected filters up by about 5x, and performed some major code cleanup on the stuff that handles collecting parameter information from the user.
Visual Studio Project Executable;
Requires .NET Framework v1.1
3/04/2005
Image Resizer A utility I wrote for my wife to make it easier for her to create e-mail friendly small versions of the many many digital pictures of our baby, so she can send them along to the grandparents. The interface is geared around providing easy bulk selection of images to process, and provides controls for resizing to a given maximum dimension, by percentage of length/width or area, or to an absolute size. It can make images bigger too, if you want that, but it's really aimed at shrinking.
Because I was going to show this app to my wife, I added a lot of finishing touches like application icons, tooltips, and a real installer.
Update: This is a re-posted version, including a slightly prettier installer with a EULA page, and some helpful file selection improvements in the UI.
Visual Studio Project .MSI Installer;
Requires .NET Framework v1.1
2/25/2005
Thread & Event Test A sample application I wrote when I was learning how to use delegates, and events to support UI-thread/Worker-thread multithreading. The sample spins a worker thread that simply counts, but uses events to periodically inform the UI of its progress. This sample is extremely well commented, as I was afraid I'd forget how this stuff works if I didn't write it down. Visual Studio Project Not Available 2/25/2005
Desktop Slideshow Desktop Slideshow has moved 4/23/2005
Battery Monitor An application that monitors battery levels for laptop/tablet pc users. Ok, so all laptops these days come with a system tray applet that does this, but this one is a little different. It runs as a mostly transparent tiny little window that sits unobtrusively down in the bottom right corner of your screen. When you mouse over it, it becomes fully opaque so you can accurately read the information, but because it's always hovering there you can just glance at it whenever you like to see your battery status--no hunting for the right icon in the system tray and hovering over it. It also demonstrates the following fun coding techniques:
  • top-level windows (stay on top even when not the active window)
  • How to platform invoke (a.k.a. "PInvoke") an API from Kernel32
  • How to completely handle painting for your form (that is, use GDI calls to exercise complete control over how your form looks)
  • Mouse event processing to perform one's own click and drag handling (with no border or title bar, you need to give the user a way to move and close the app).
  • Hooking into SystemEvent events that aren't exposed in the Visual Studio forms designer in order to process events like power state changes and screen rotations.
Visual Studio Project Executable;
Requires .NET Framework v1.1
9/9/2005

Articles

Ok, so right now there's only one article. But You have to start somewhere, right?

HHHH Custom Control Library

Ok, here it is: HHHHControls.zip (193k, 8/26/2005).

The library contains, at present, the following three controls:
DBAnim

A double-bufferred animation control. I got irritated at how difficult it is to get WinForms applications to refresh the screen at just the moment you would like, so this is my solution. The basic usage pattern for this control is:

  1. Add the control to your form at design time
  2. At run-time, create a Bitmap object that's the size of the control, and set the control's .Frame property to it:
    Bitmap B = new Bitmap(dBAnim1.Width, dBAnim1.Height);
    dbAnim1.Frame = B;
  3. Whenever you like, modify the contents of the bitmap:
    using(Graphics G = Graphics.FromImage(B)) {
    // do some drawing... }
  4. When you're done messing with the bitmap, call the control's Update() method. The control will refresh its surface with whatever is now in the Bitmap, and will do the little bit of WinForms voodoo necessary for the changes to show up on the screen.

That's about all there is to it. Basically, you create a "frame" that you draw into, and periodically you tell DBAnim to re-display the frame. Note that for performance reasons, you really should ensure that the bitmap the control is using is the same size as the control itself; if your application re-sizes the control at runtime (in response to, say, the user resizing your form), you should create a new bitmap for the new size, re-render the contents, and re-assign to the control's .Frame member. See the DBAnimTester project for an example (start the animation and then resize the form to see what I mean about performance).

ImagePreviewPanel

The idea behind ImagePreviewPanel is that you give it a set of Image objects (or filenames), it will make thumbnails of them, and display a single line of them to the user. The thumbnails actually displayed are a "window" onto the full list being maintained by the control; that is, you can give the control 20 images to work with, but have it display only 4 of them at a time if you like. ImagePreviewPanel also supports the concept of a selection (and has a corresponding SelectedIndex property like other collections). If you like (and if the currently selected thumbnail is actually one of the ones being displayed) you can have the ImagePreviewPanel display a nifty highlight to indicate which item is selected. Here's a picture:

Ok, so the picture isn't that exciting, but if you look close you can see the pretty white-gradient highlight around the middle image (you have no idea how much of a pain that stupid effect was to do). ImagePreviewPanel is by far the most complicated control I have written, and it probably has some bugs in it. If you find one, please tell me about it. See the ImagePreviewPanelTester project for an example of how to use this control.

RampSlider I wanted a slider control that displayed its value as a sort of ramp-shaped bar graph. Other than that, it's just like an ordinary slider control. Here's a picture of a control with min=0, max=15, value=6:

See the RampSliderTester project for an example of how to use this control.