OpenTK - Simple Movable Sprite

March 29, 2011.netopengl

I wrote my second OpenTK app. This time I'm drawing a sprite which you can move around the screen using the keyboard. I've included the source code after the jump or you can download it.

Read More

Keeping SplitContainer SplitterDistance consistent

February 9, 2011.netwinforms

If you're having trouble keeping the SplitterDistance property of a SplitContainer consistent across app sessions, you can set the FixedPanel property of the splitter to FixedPanel.Panel1.

splitter.FixedPanel = FixedPanel.Panel1;

I guess this could also work with FixedPanel.Panel2 as well but I haven't given it a try. Credit this stackoverflow post.

Favoring Composition over Inheritance

You may have heard the expression before "Favor Composition over Inheritance", but do you know what it means and how to apply it? Lets take this code for example:

abstract class Car
{
    public Color Color { get; protected set; }
    public Engine Engine { get; protected set; }
}

class ElectricCar : Car
{
    public ElectricCar()
    {
        this.Color = Color.Blue;
        this.Engine = new ElectricEngine();
    }
}

class SportsCar : Car
{
    public SportsCar()
    {
        this.Color = Color.Red;
        this.Engine = new V8Engine();
    }
}

class Truck : Car
{
    public Truck()
    {
        this.Color = Color.White;
        this.Engine = new DieselEngine();
    }
}

In this contrived example, we've defined three types of cars. Each instance of each of the cars will always have the same color and same engine. What happens when we need a 4th type? We have to define another class. By refactoring this code, we can compose a car type by giving it a color and an engine:

class Car
{
    public Color Color { get; private set; }
    public Engine Engine { get; private set; }
    
    public Car(Color color, Engine engine)
    {
        this.Color = color;
        this.Engine = engine;
    }
}

Car electricCar = new Car(Color.Blue, new ElectricEngine());
Car sportsCar = new Car(Color.Red, new V8Engine());
Car truck = new Car(Color.White, new DieselEngine());
Car familyCar = new Car(Color.Black, new V4Engine());

Now we can compose many car types, with any combination of colors and engines and we've only defined one class.

Component Glue

The other day I started an open source project for an IoC Container I call Component Glue. It's in a toy / learning tool status right now and I don't know how far I actually want to take the project. More to come though.

Component Glue on Codeplex

Visual Studio - Move referenced DLL to different directory after Build

July 20, 2010.netmsbuild

If you need to move a referenced DLL to a different directory after build, add these commands to the "Post Build event command line" box in the "Build Events" tab of the project properties:

mkdir $(TargetDir)dir
move $(TargetDir)myDLL.dll $(TargetDir)dir\myDLL.dll