views:

55

answers:

1

Hi, I'm trying to write my own abstraction over the MessageBoxImage enumeration, and see that MessageBoxImage is defined as:

namespace System.Windows
  {
      public enum MessageBoxImage
      {
          None = 0,
          Error = 16,
          Hand = 16,
          Stop = 16,
          Question = 32,
          Exclamation = 48,
          Warning = 48,
          Asterisk = 64,
          Information = 64,
      }
  }

How does the Show method determine whether to display an Error image or a Hand image? How would I write a method which takes a MessageBoxImage type, and return a CustomMessageBoxImage type which maps to the MessageBoxImage type, as I can't include both MessageBoxImage.Error and MessageBoxImage.Hand in the same switch statement?

+1  A: 

Historically there were different icons that ended up being merged into a single actual icon image. So there are several enumerated type values (Hand and Stop for example) that simply mean the same thing in modern Windows OSes. There is no difference between them, they are simply aliases.

If you want to have new values to represent differences, then you could use a secondary variable (e.g. "isError) to convey the difference you wish to apply between Stop and Hand. Or you could copy the Icon value into an int and set a high bit in the value to indicate this extra information so it can be "carried" within a single variable. Or you could use your own enumeration that is "unrelated" to the MessageBoxIcon, and have methods that convert from your value to the MessageBoxIcon value.

I'd suggest having your own "Status" value and then converting that into an Icon value as needed - the two are conveying quite different information, so trying to overload (corrupt) the MessageBox value to convey extra information wouldn't be a very good approach.

Jason Williams
Thanks Jason, I'll take that approach
devdigital