有没有办法来组合枚举在VB.net?
Is there a way to combine Enums in VB.net?
我相信你想要的是一个标志枚举类型。
I believe what you want is a flag type enum.
您需要添加标记属性来枚举的顶部,然后你可以结合枚举与'或'关键字。
You need to add the Flags attribute to the top of the enum, and then you can combine enums with the 'Or' keyword.
这样的:
<Flags()> _
Enum CombinationEnums As Integer
HasButton = 1
TitleBar = 2
ReadOnly = 4
ETC = 8
End Enum
注意:的数字向右总是两倍大(2的幂) - 这是需要能够分离已经设置了单独标记
Note: The numbers to the right are always twice as big (powers of 2) - this is needed to be able to separate the individual flags that have been set.
联合使用或关键字所需的标志:
Combine the desired flags using the Or keyword:
Dim settings As CombinationEnums
settings = CombinationEnums.TitleBar Or CombinationEnums.Readonly
此设置标题栏,并只读到枚举
This sets TitleBar and Readonly into the enum
要检查什么的被设置:
If (settings And CombinationEnums.TitleBar) = CombinationEnums.TitleBar Then
Window.TitleBar = True
End If