Articles tagged with .NET

Suppressing CA1062 with a Helper Function

By Eric — 4 minute read

I think Visual Studio's static analysis warning for checking parameters for null before they are used is generally a good idea, but the code to check the parameters can get really tedious.

Before addressing the tedium, though, why does it even matter whether you check for null arguments and throw …

Read more...

.NET Color Struct Equality

By Eric

When is white not white? When one is Color.White and the other is Color.FromArgb(0xff, 0xff, 0xff, 0xff).

I was trying to data bind a list of colors to a ComboBox and have the SelectedValue property bound to a particular color. The frustrating thing was that even though …

Read more...

Transparent WinForms Label

By Eric — 2 minute read

Easy control transparency isn't exactly a hallmark of Windows Forms. If you have a form with a background image or a gradient, the stock controls paint with a solid background to give a criminally egregious aesthetic.

If you search the web for a solution, you might come up with a …

Read more...

Rounded Rectangluar Regions

By Eric — 4 minute read

There are lots of examples that demonstrate how to draw a rectangle with rounded corners using GDI+ in .NET. Converting such a rectangle to a Region so that it can be filled or be used for the geometry of a window can have less than perfect results, though.

For example …

Read more...

The Best of PDC 2008

By Eric — 5 minute read

For those of us poor folk who didn't make it to PDC this past fall, Microsoft has been taking the show to us in the form of its MSDN Unleashed series. Rob Bagby, developer evangelist, came to Salt Lake City to present and give updates about new and upcoming technologies …

Read more...

.NET Cold Startup Performance: More

By Eric — 2 minute read

A few months ago I wrote about an approach to improving .NET cold startup performance. Here's a little more information that I've learned since then.

Another useful tool for optimizing cold startup is Microsoft's free CLR Profiler 2.0. While this tool has the aesthetics of a wadded-up paper sack …

Read more...

Are .NET Properties a Mistake?

By Eric — 1 minute read

As I mentioned the other day, I'm reading Jeffrey Richter's book CLR via C# right now. I was kind of surprised to read this statement by the author: "If I had been involved in the design of the .NET Framework and compilers, I would not have offered properties at all …

Read more...

.NET Cold Startup Performance: An Example

By Eric — 6 minute read

When running a .NET application for the first time after rebooting or hibernating the computer, you might find that it takes a long time to start up. I've been trying to address this problem in a few situations recently. In spite of having read several articles on the subject, I …

Read more...

Getting the Host's Main Window Handle in an Office Add-in

By Eric — 1 minute read

Sometimes you want the window handle of the host application when you're writing an Office add-in. Excel includes that as a property of the Application object in newer versions of the object model, but Word and PowerPoint don't. I seem to remember some sample code from Microsoft that suggests using …

Read more...

Why StringComparison.Ordinal Is Usually the Right Choice

By Eric — 2 minute read

A question that arose in response to my previous post (about how string comparisons can produce unexpected results when done in a culture-sensitive way) was Which is right, StringComparison.Ordinal or StringComparison.InvariantCulture? The short answer: StringComparison.Ordinal.

There is a good article explaining the differences between the StringComparison enum …

Read more...