gpt4 book ai didi

vb.net - 如何获取 ColorDialog 中使用的基本颜色的值?

转载 作者:行者123 更新时间:2023-12-01 05:46:49 26 4
gpt4 key购买 nike

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

是否有可能以类似的方式获得 48 种基本颜色?

最佳答案

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

表格代码

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

关于vb.net - 如何获取 ColorDialog 中使用的基本颜色的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1285637/

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