为什么System.Windows.MessageBoxImage具有枚举子项具有相同的价值? [英] Why does System.Windows.MessageBoxImage have enumeration sub-items with the same value?

查看:353
本文介绍了为什么System.Windows.MessageBoxImage具有枚举子项具有相同的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写我自己的抽象在MessageBoxImage枚举,并看到MessageBoxImage定义为:

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,
      }
  }

如何显示的方法确定是否显示错误图像或手的形象? 我怎么会写一个方法,它需要一个MessageBoxImage类型,并返回其映射到MessageBoxImage类型CustomMessageBoxImage类型,因为我不能在同一个switch语句包括MessageBoxImage.Error和MessageBoxImage.Hand?

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?

推荐答案

在历史上有不同的图标最终被合并成一个实际的图标图像。因此,有几个枚举类型值(手动和停止为例),其仅仅意味着现代的Windows操作系统同样的事情。他们之间没有什么区别,他们只是别名。

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.

如果你想有新的价值观来重新present差异,那么你可以使用一个辅助变量(如ISERROR)传达你希望停止和手之间的应用差别。或者你也可以复制的图标值为一个int,并设置较高位的值来表示这些额外的信息,因此可以携带在一个单一的变量。或者你可以用你自己的枚举是无关的MessageBoxIcon,并从转换方法你的价值为MessageBoxIcon值。

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.

我建议拥有自己的状态的值,然后转换到这一点是需要一个图标价值 - 两者传送完全不同的信息,所以尝试过载(腐败)在MessageBox价值传达额外的信息就不会是一个非常不错的办法。

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.

这篇关于为什么System.Windows.MessageBoxImage具有枚举子项具有相同的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆