Kleine Anregung ....
Public Class ColorDia
Public Property title As String
Set(value As String)
Me.Text = value
End Set
Get
Return Me.Text
End Get
End Property
Public Property Color As Color
Public WriteOnly Property CustomColors As List(Of Color)
Set(value As List(Of Color))
Dim max As Integer = Math.Min(value.Count - 1, 24)
For i As Integer = 0 To max
ColorLabels(i).BackColor = value(i)
Next i
End Set
End Property
Public Event ColorChanged(ByVal sender As Object, usercolor As Color)
Private ColorLabels As New List(Of Label)
Private red As New VScrollBar With _
{.Parent = Me, .Left = 150, .Width = 30, .Maximum = 255, .LargeChange = _
1}
Private green As New VScrollBar With _
{.Parent = Me, .Left = 190, .Width = 30, .Maximum = 255, .LargeChange = _
1}
Private blue As New VScrollBar With _
{.Parent = Me, .Left = 230, .Width = 30, .Maximum = 255, .LargeChange = _
1}
Public Sub New()
InitializeComponent()
For i As Integer = 0 To 4
For k As Integer = 0 To 4
Dim loc As Point = New Point(k * 22, i * 22)
Dim lb As New Label With _
{.Location = loc, .Size = New Size(20, 20), .Parent = Me}
lb.BackColor = Color.FromArgb(i * 50, k * 50, (i + k) * 25)
AddHandler lb.Click, AddressOf LabelClick
ColorLabels.Add(lb)
Next k
Next i
Me.Text = "Farbauswahl"
AddHandler red.ValueChanged, AddressOf ValueChanged
AddHandler green.ValueChanged, AddressOf ValueChanged
AddHandler blue.ValueChanged, AddressOf ValueChanged
End Sub
Private Sub ColorDia_Load(sender As System.Object, _
e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
Me.Size = New Size(300, 200)
Me.MaximizeBox = False
End Sub
Private Sub LabelClick(ByVal sender As Object, e As EventArgs)
Color = DirectCast(sender, Label).BackColor
RaiseEvent ColorChanged(Me, Color)
End Sub
Private Sub ValueChanged(ByVal sender As Object, e As EventArgs)
Color = Color.FromArgb(red.Value, green.Value, blue.Value)
RaiseEvent ColorChanged(Me, Color)
End Sub
End Class Anwendung:
Private Sub Button1_Click(sender As System.Object, _
e As System.EventArgs) Handles Button1.Click
Using cd As New ColorDia
AddHandler cd.ColorChanged, AddressOf colorchanged
cd.title = "Demo zur farbauswahl"
cd.Color = Color.Magenta
cd.CustomColors = _
New List(Of Color)(New Color() {Color.Red, Color.Yellow, _
Color.Magenta})
cd.ShowDialog()
Me.BackColor = cd.Color
End Using
End Sub
Public Sub colorchanged(sender As Object, usercolor As Color)
Me.BackColor = usercolor
End Sub |