如何获取 ColorDialog 中使用的基本颜色的值?

发布于 2024-08-01 23:46:40 字数 145 浏览 6 评论 0原文

我可以使用 myColorDialog.CustomColors 获取 ColorDialog (vb.net) 中使用的自定义颜色,这将返回一个整数值颜色数组。

是否可以用类似的方法得到48种基本颜色?

I can get the custom colours used in the ColorDialog (vb.net) by using myColorDialog.CustomColors, which will return me an array of colours as integer values.

Is it possible to get the 48 Basic Colors in a similar way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

和影子一齐双人舞 2024-08-08 23:46:41

幸运的是,我刚刚制作了一个自定义颜色对话框。
看看你是否喜欢它..

表单代码

Imports System.Drawing
    Public Class Form1
    Dim lbl() As Windows.Forms.Label
     Public t_Color As Color
       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim colorsArray As System.Array = [Enum].GetValues(GetType(KnownColor))
    Dim colorNames As System.Array = [Enum].GetNames(GetType(KnownColor))
    Dim clr As Color
    clr = Color.FromKnownColor(colorsArray(30))
    'MsgBox(colorsArray.Length)
    Dim indx() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
    Dim Xindex, Yindex As Integer
    Dim tmp
    ReDim lbl(colorsArray.Length)
    Me.Size = New Size(505, 312)
    For i = 0 To colorsArray.Length - 1
        tmp = i Mod 14
        Xindex = indx(tmp)
        Yindex = Int(i / 14)

        lbl(i) = New Windows.Forms.Label
        lbl(i).AutoSize = False
        lbl(i).Size = New Size(30, 15)
        lbl(i).BackColor = Color.FromKnownColor(colorsArray(i))
        lbl(i).Tag = colorNames(i).ToString
        lbl(i).Location = New Point((Xindex * 35) + 5, (Yindex * 20) + 40)
        lbl(i).BorderStyle = Windows.Forms.BorderStyle.FixedSingle
        'lbl(i)
        AddHandler lbl(i).MouseMove, AddressOf Label1_MouseMove
        AddHandler lbl(i).MouseHover, AddressOf Label1_MouseHover
        AddHandler lbl(i).Click, AddressOf Label1_Click
        Me.Controls.Add(lbl(i))
    Next
    lbl(colorsArray.Length) = New Windows.Forms.Label
    lbl(colorsArray.Length).Location = New Point(lbl(colorsArray.Length - 1).Location.X + 5, lbl(colorsArray.Length - 1).Location.Y)
    lbl(colorsArray.Length).AutoSize = True
    lbl(colorsArray.Length).Font = Me.Font
    Me.Size = New Size(502, 328)
    Me.Show()

End Sub

Private Sub Label1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.Click
    Me.DialogResult = Windows.Forms.DialogResult.OK
    sender.backcolor()
    Me.Close()
End Sub

Private Sub Label1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseHover
    'Label2.Text = sender.backcolor.toknowncolor.ToString

End Sub


Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
    Label2.Text = sender.backcolor.toknowncolor.ToString
    t_Color = sender.backcolor
End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

End Sub
  End Class

表单设计

       $
     <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
     Partial Class Form1
    Inherits System.Windows.Forms.Form

  'Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    Try
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
    Finally
        MyBase.Dispose(disposing)
    End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.  
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Me.components = New System.ComponentModel.Container()
    Me.Label1 = New System.Windows.Forms.Label()
    Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
    Me.Label2 = New System.Windows.Forms.Label()
    Me.SuspendLayout()
    '
    'Label1
    '
    Me.Label1.BackColor = System.Drawing.Color.Black
    Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    Me.Label1.Location = New System.Drawing.Point(18, 11)
    Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(60, 0)
    Me.Label1.TabIndex = 0
    Me.Label1.Text = "Label1"
    '
    'Label2
    '
    Me.Label2.AutoSize = True
    Me.Label2.BackColor = System.Drawing.Color.Transparent
    Me.Label2.Location = New System.Drawing.Point(164, 9)
    Me.Label2.Name = "Label2"
    Me.Label2.Size = New System.Drawing.Size(55, 16)
    Me.Label2.TabIndex = 1
    Me.Label2.Text = "Label2"
    '
    'Form1
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(9.0!, 16.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(1185, 494)
    Me.ControlBox = False
    Me.Controls.Add(Me.Label2)
    Me.Controls.Add(Me.Label1)
    Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.Margin = New System.Windows.Forms.Padding(4)
    Me.Name = "Form1"
    Me.Text = "Click on Colour to Select"
    Me.ResumeLayout(False)
    Me.PerformLayout()

End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents Label2 As System.Windows.Forms.Label
End Class

Luckily I have just made a custom Color Dialog box.
See if you like it..

Form Code

Imports System.Drawing
    Public Class Form1
    Dim lbl() As Windows.Forms.Label
     Public t_Color As Color
       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim colorsArray As System.Array = [Enum].GetValues(GetType(KnownColor))
    Dim colorNames As System.Array = [Enum].GetNames(GetType(KnownColor))
    Dim clr As Color
    clr = Color.FromKnownColor(colorsArray(30))
    'MsgBox(colorsArray.Length)
    Dim indx() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
    Dim Xindex, Yindex As Integer
    Dim tmp
    ReDim lbl(colorsArray.Length)
    Me.Size = New Size(505, 312)
    For i = 0 To colorsArray.Length - 1
        tmp = i Mod 14
        Xindex = indx(tmp)
        Yindex = Int(i / 14)

        lbl(i) = New Windows.Forms.Label
        lbl(i).AutoSize = False
        lbl(i).Size = New Size(30, 15)
        lbl(i).BackColor = Color.FromKnownColor(colorsArray(i))
        lbl(i).Tag = colorNames(i).ToString
        lbl(i).Location = New Point((Xindex * 35) + 5, (Yindex * 20) + 40)
        lbl(i).BorderStyle = Windows.Forms.BorderStyle.FixedSingle
        'lbl(i)
        AddHandler lbl(i).MouseMove, AddressOf Label1_MouseMove
        AddHandler lbl(i).MouseHover, AddressOf Label1_MouseHover
        AddHandler lbl(i).Click, AddressOf Label1_Click
        Me.Controls.Add(lbl(i))
    Next
    lbl(colorsArray.Length) = New Windows.Forms.Label
    lbl(colorsArray.Length).Location = New Point(lbl(colorsArray.Length - 1).Location.X + 5, lbl(colorsArray.Length - 1).Location.Y)
    lbl(colorsArray.Length).AutoSize = True
    lbl(colorsArray.Length).Font = Me.Font
    Me.Size = New Size(502, 328)
    Me.Show()

End Sub

Private Sub Label1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.Click
    Me.DialogResult = Windows.Forms.DialogResult.OK
    sender.backcolor()
    Me.Close()
End Sub

Private Sub Label1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseHover
    'Label2.Text = sender.backcolor.toknowncolor.ToString

End Sub


Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
    Label2.Text = sender.backcolor.toknowncolor.ToString
    t_Color = sender.backcolor
End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

End Sub
  End Class

Forrm DEsign

       $
     <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
     Partial Class Form1
    Inherits System.Windows.Forms.Form

  'Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    Try
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
    Finally
        MyBase.Dispose(disposing)
    End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.  
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Me.components = New System.ComponentModel.Container()
    Me.Label1 = New System.Windows.Forms.Label()
    Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
    Me.Label2 = New System.Windows.Forms.Label()
    Me.SuspendLayout()
    '
    'Label1
    '
    Me.Label1.BackColor = System.Drawing.Color.Black
    Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    Me.Label1.Location = New System.Drawing.Point(18, 11)
    Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(60, 0)
    Me.Label1.TabIndex = 0
    Me.Label1.Text = "Label1"
    '
    'Label2
    '
    Me.Label2.AutoSize = True
    Me.Label2.BackColor = System.Drawing.Color.Transparent
    Me.Label2.Location = New System.Drawing.Point(164, 9)
    Me.Label2.Name = "Label2"
    Me.Label2.Size = New System.Drawing.Size(55, 16)
    Me.Label2.TabIndex = 1
    Me.Label2.Text = "Label2"
    '
    'Form1
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(9.0!, 16.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(1185, 494)
    Me.ControlBox = False
    Me.Controls.Add(Me.Label2)
    Me.Controls.Add(Me.Label1)
    Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.Margin = New System.Windows.Forms.Padding(4)
    Me.Name = "Form1"
    Me.Text = "Click on Colour to Select"
    Me.ResumeLayout(False)
    Me.PerformLayout()

End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents Label2 As System.Windows.Forms.Label
End Class
烟柳画桥 2024-08-08 23:46:41

我花了很多时间寻找一种以编程方式获取基本颜色列表的方法,但没有找到这样的方法。
我当前的解决方案=):

List<Color> basicColors = new List<Color>
            {
                Color.FromArgb(255, 255, 128, 128),
                Color.FromArgb(255, 255, 255, 128),
                Color.FromArgb(255, 128, 255, 128),
                Color.FromArgb(255, 0, 255, 128),
                Color.FromArgb(255, 128, 255, 255),
                Color.FromArgb(255, 0, 128, 255),
                Color.FromArgb(255, 255, 128, 192),
                Color.FromArgb(255, 255, 128, 255),
                Color.FromArgb(255, 255, 0, 0),
                Color.FromArgb(255, 255, 255, 0),
                Color.FromArgb(255, 128, 255, 0),
                Color.FromArgb(255, 0, 255, 64),
                Color.FromArgb(255, 0, 255, 255),
                Color.FromArgb(255, 0, 128, 192),
                Color.FromArgb(255, 128, 128, 192),
                Color.FromArgb(255, 255, 0, 255),
                Color.FromArgb(255, 128, 64, 64),
                Color.FromArgb(255, 255, 128, 64),
                Color.FromArgb(255, 0, 255, 0),
                Color.FromArgb(255, 0, 128, 128),
                Color.FromArgb(255, 0, 64, 128),
                Color.FromArgb(255, 128, 128, 255),
                Color.FromArgb(255, 128, 0, 64),
                Color.FromArgb(255, 255, 0, 128),
                Color.FromArgb(255, 128, 0, 0),
                Color.FromArgb(255, 255, 128, 0),
                Color.FromArgb(255, 0, 128, 0),
                Color.FromArgb(255, 0, 128, 64),
                Color.FromArgb(255, 0, 0, 255),
                Color.FromArgb(255, 0, 0, 160),
                Color.FromArgb(255, 128, 0, 128),
                Color.FromArgb(255, 128, 0, 255),
                Color.FromArgb(255, 64, 0, 0),
                Color.FromArgb(255, 128, 64, 0),
                Color.FromArgb(255, 0, 64, 0),
                Color.FromArgb(255, 0, 64, 64),
                Color.FromArgb(255, 0, 0, 128),
                Color.FromArgb(255, 0, 0, 64),
                Color.FromArgb(255, 64, 0, 64),
                Color.FromArgb(255, 64, 0, 128),
                Color.FromArgb(255, 0, 0, 0),
                Color.FromArgb(255, 128, 128, 0),
                Color.FromArgb(255, 128, 128, 64),
                Color.FromArgb(255, 128, 128, 128),
                Color.FromArgb(255, 64, 128, 128),
                Color.FromArgb(255, 192, 192, 192),
                Color.FromArgb(255, 64, 0, 64),
                Color.FromArgb(255, 255, 255, 255)
            };

I spent a lot of time in the search of a way to get a list of basic colors programmatically, but did not find such a method.
My current solution =) :

List<Color> basicColors = new List<Color>
            {
                Color.FromArgb(255, 255, 128, 128),
                Color.FromArgb(255, 255, 255, 128),
                Color.FromArgb(255, 128, 255, 128),
                Color.FromArgb(255, 0, 255, 128),
                Color.FromArgb(255, 128, 255, 255),
                Color.FromArgb(255, 0, 128, 255),
                Color.FromArgb(255, 255, 128, 192),
                Color.FromArgb(255, 255, 128, 255),
                Color.FromArgb(255, 255, 0, 0),
                Color.FromArgb(255, 255, 255, 0),
                Color.FromArgb(255, 128, 255, 0),
                Color.FromArgb(255, 0, 255, 64),
                Color.FromArgb(255, 0, 255, 255),
                Color.FromArgb(255, 0, 128, 192),
                Color.FromArgb(255, 128, 128, 192),
                Color.FromArgb(255, 255, 0, 255),
                Color.FromArgb(255, 128, 64, 64),
                Color.FromArgb(255, 255, 128, 64),
                Color.FromArgb(255, 0, 255, 0),
                Color.FromArgb(255, 0, 128, 128),
                Color.FromArgb(255, 0, 64, 128),
                Color.FromArgb(255, 128, 128, 255),
                Color.FromArgb(255, 128, 0, 64),
                Color.FromArgb(255, 255, 0, 128),
                Color.FromArgb(255, 128, 0, 0),
                Color.FromArgb(255, 255, 128, 0),
                Color.FromArgb(255, 0, 128, 0),
                Color.FromArgb(255, 0, 128, 64),
                Color.FromArgb(255, 0, 0, 255),
                Color.FromArgb(255, 0, 0, 160),
                Color.FromArgb(255, 128, 0, 128),
                Color.FromArgb(255, 128, 0, 255),
                Color.FromArgb(255, 64, 0, 0),
                Color.FromArgb(255, 128, 64, 0),
                Color.FromArgb(255, 0, 64, 0),
                Color.FromArgb(255, 0, 64, 64),
                Color.FromArgb(255, 0, 0, 128),
                Color.FromArgb(255, 0, 0, 64),
                Color.FromArgb(255, 64, 0, 64),
                Color.FromArgb(255, 64, 0, 128),
                Color.FromArgb(255, 0, 0, 0),
                Color.FromArgb(255, 128, 128, 0),
                Color.FromArgb(255, 128, 128, 64),
                Color.FromArgb(255, 128, 128, 128),
                Color.FromArgb(255, 64, 128, 128),
                Color.FromArgb(255, 192, 192, 192),
                Color.FromArgb(255, 64, 0, 64),
                Color.FromArgb(255, 255, 255, 255)
            };
離殇 2024-08-08 23:46:41

它们可作为 struct System.Drawing.Color 的静态属性使用。

示例:

Color.AliceBlue
Color.AntiqueWhite
Color.Aqua

等。

编辑:抱歉,这里的内容比对话框中的多,所以它可能不是您想要的。

They are available as static properties of the struct System.Drawing.Color

Examples:

Color.AliceBlue
Color.AntiqueWhite
Color.Aqua

etc.

Edit: Sorry, there are more here than in the dialog, so it may not be what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文