gpt4 book ai didi

c# - ContentAlignment 枚举值的解释

转载 作者:太空宇宙 更新时间:2023-11-03 19:01:33 27 4
gpt4 key购买 nike

System.Drawing.ContentAlignment 枚举如下所示:

namespace System.Drawing
{
// Summary:
// Specifies alignment of content on the drawing surface.
[Editor("System.Drawing.Design.ContentAlignmentEditor, System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public enum ContentAlignment
{
TopLeft = 1,
TopCenter = 2,
TopRight = 4,
MiddleLeft = 16,
MiddleCenter = 32,
MiddleRight = 64,
BottomLeft = 256,
BottomCenter = 512,
BottomRight = 1024,
}
}

为什么以某种标志样式定义值?为什么缺少 8 和 128?

最佳答案

也许让 ContentAlignment 枚举参与按位运算。

But why it isn't decorated with FlagsAttribute?

因为它不打算被客户端用作按位标志,所以他们没有用 FlagsAttribute 修饰枚举。

您可以引用 .net framework 源代码以了解它们如何很好地使用 ContentAlignment 进行按位运算。

ControlPaint.TranslateAlignment使用它,您可以在 top of the class 中看到带有按位或的声明

private static readonly ContentAlignment anyRight  = ContentAlignment.TopRight | ContentAlignment.MiddleRight | ContentAlignment.BottomRight;
private static readonly ContentAlignment anyBottom = ContentAlignment.BottomLeft | ContentAlignment.BottomCenter | ContentAlignment.BottomRight;
private static readonly ContentAlignment anyCenter = ContentAlignment.TopCenter | ContentAlignment.MiddleCenter | ContentAlignment.BottomCenter;
private static readonly ContentAlignment anyMiddle = ContentAlignment.MiddleLeft | ContentAlignment.MiddleCenter | ContentAlignment.MiddleRight;

这应该回答“为什么以某种标志样式定义值”。

Why are 8 and 128 missing?

我对此一无所知。如果有人有,将不胜感激。

关于c# - ContentAlignment 枚举值的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34961482/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com