Category Archives: C#

C# topics

Setting the order of properties in an ExpandableObjectConverter

When inheriting from an ExpandableObjectConverter to display custom properties in a PropertyGrid, you will often want to set the order of the properties instead of having them in alphabetical order. To do this you just need to override the GetProperties … Continue reading

Posted in .net, C#, Programming | Tagged , , , , , , | Leave a comment

C# Snippet for Accessing Bitmap Data with Unsafe Code

Since GetPixel is slow and I keep having to access bitmap data with unsafe code, I thought it would be a nice thing to make into a snippet.

Posted in .net, C#, Programming | Tagged , , , , , , | Leave a comment

Image.Clone does not unlock the file

Turns out, copying an image using Clone really does make an exact copy. You can’t just open an image, clone it, then safely close it as you might expect, because it also copies the file lock. Instead, copy the image … Continue reading

Posted in .net, C#, Programming, Uncategorized | Tagged , , , , , , , | 1 Comment

Automatically Fill a ComboBox with an Enum

This is a really nice little feature. If we have an enumerator, say: public enum MyEnumerator { Oranges, Apples, Hedgehogs, Laptops, Budgies, Other } Having a form with a ComboBox called comboBox1, put this in the constructor/form load etc: this.comboBox1.DataSource … Continue reading

Posted in .net, C#, Programming | Tagged , , , , , | 1 Comment

TextRenderer is slow, DrawString is wrong

After struggling with WinAPI code and hacks in .NET 1.0 I was really looking forward to the TextRenderer class when I first heard about it. But as it turns out, not only is TextRenderer horrible at measuring character size it … Continue reading

Posted in .net, C#, Programming | Tagged , , , , , , , , | 2 Comments

Dragging and dropping onto a RichTextBox

One of many flaws with the RichTextBox control is its lack of support for drag/drop operations. Luckily it’s simple to add. In fact, it’s so simple you’ll wonder why they didn’t just support it out of the box.

Posted in .net, C#, Programming | Tagged , , , , , , , , , , | Leave a comment

Making sure a number is between 0 and 255

Recently while reworking the code for the Ascgen dotNET I needed to make sure that a variable is between 0 and 255 before converting it to a byte, and I needed it to be as fast as possible since it … Continue reading

Posted in .net, C#, Programming | Tagged , , , , , , , , , , , , , | Leave a comment