定义将出现在colordialog中的特定自定义颜色?

l--*_*''' 3 vb.net winforms

是否有可能在winforms,vb.net中定义将出现在colordialog的自定义颜色框中的特定自定义颜色?

Mar*_*ell 5

简而言之,是的.MSDN 在此处介绍它.问题是它不是通过Color- 你需要处理BGR设置的值 - 即每个整数由颜色组成00BBGGRR,所以你左移蓝色16,绿色8,并使用红色"as是".

我的VB糟透了,但在C#中,添加紫色:

    using (ColorDialog dlg = new ColorDialog())
    {
        Color purple = Color.Purple;
        int i = (purple.B << 16) | (purple.G << 8) | purple.R;
        dlg.CustomColors = new[] { i };
        dlg.ShowDialog();
    }
Run Code Online (Sandbox Code Playgroud)

反射器向我保证这类似于:

Using dlg As ColorDialog = New ColorDialog
    Dim purple As Color = Color.Purple
    Dim i As Integer = (((purple.B << &H10) Or (purple.G << 8)) Or purple.R)
    dlg.CustomColors = New Integer() { i }
    dlg.ShowDialog
End Using
Run Code Online (Sandbox Code Playgroud)


Gab*_*bby 5

如果您想拥有多于1种自定义颜色,可以执行以下操作:

            'Define custom colors
    Dim cMyCustomColors(1) As Color
    cMyCustomColors(0) = Color.FromArgb(0, 255, 255) 'aqua
    cMyCustomColors(1) = Color.FromArgb(230, 104, 220) 'bright pink

    'Convert colors to integers
    Dim colorBlue As Integer
    Dim colorGreen As Integer
    Dim colorRed As Integer
    Dim iMyCustomColor As Integer
    Dim iMyCustomColors(cMyCustomColors.Length - 1) As Integer

    For index = 0 To cMyCustomColors.Length - 1
        'cast to integer
        colorBlue = cMyCustomColors(index).B
        colorGreen = cMyCustomColors(index).G
        colorRed = cMyCustomColors(index).R

        'shift the bits
        iMyCustomColor = colorBlue << 16 Or colorGreen << 8 Or colorRed

        iMyCustomColors(index) = iMyCustomColor
    Next

    ColorDialog1.CustomColors = iMyCustomColors
    ColorDialog1.ShowDialog()
Run Code Online (Sandbox Code Playgroud)