gpt4 book ai didi

winforms - 将 argb 转换为字符串

转载 作者:行者123 更新时间:2023-12-02 22:14:57 24 4
gpt4 key购买 nike

哪种方法允许将 ARGB 转换为字符串作为 'int, int, int' ?例子。 $Main 背景颜色设置为字符串 '0, 100, 200' 。返回 $Main.BackColor 给出 ARGB 但不是字符串 '0, 100, 200':

$Main  = [System.Windows.Forms.Form] @{
BackColor = '0, 100, 200'
}

$Main.BackColor
--------------
R : 0
G : 100
B : 200
A : 255
IsKnownColor : False
IsEmpty : False
IsNamedColor : False
IsSystemColor : False
Name : ff0064c8
To.String() 方法返回结果 Color [A=255, R=0, G=100, B=200].这不是预期的。

目前我正在这样做:
 ('R', 'G', 'B').ForEach({ $Main.BackColor.$_ }) -join ', '

--------------
0, 100, 200

但是,我希望有特殊的方法可以将 as ARGB 转换为 string ,将 string 转换为 ARGB 。这些方法是什么?谢谢

最佳答案

这个问题有一些很好的主动答案,但看起来所有人都忽略了正确的方法,使用类型转换器。有一个 ColorConverter 负责 ConvertToConvertFrom String/Color:

$Color = [System.Drawing.Color]'0, 100, 200'
[System.Drawing.ColorConverter]::new().ConvertToString($Color)
# Result: 0, 100, 200
这与 PropertyGrid 用于将字符串转换为 ColorColor 的类相同,反之亦然。
它也会处理颜色的 A 元素,例如,如果您创建像 100, 0, 100, 200 这样的颜色。此解决方案在需要时自动包含或忽略 A 部分:
$Color = [System.Drawing.Color]'100, 0, 100, 200'
[System.Drawing.ColorConverter]::new().ConvertToString($Color)
# Result: 100, 0, 100, 200

关于winforms - 将 argb 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60283188/

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