Author Topic: Color Picker  (Read 3173 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Color Picker
« on: September 16, 2017, 02:52:50 PM »
This is a color picker that uses the same picker used by the properties window.

Phrog30

  • Guest
Re: Color Picker
« Reply #1 on: September 16, 2017, 03:10:20 PM »
Thanks Archie...

Godra

  • Hero Member
  • *****
  • Posts: 1436
    • View Profile
Re: Color Picker
« Reply #2 on: October 22, 2017, 06:49:16 PM »
As it appears, color picking can also be done just by calling a ColorDialog box within the Click event of a control.

Here is a simple example with a standard button control placed on the MainForm and some code from the ColorPicker.vb control posted by Archie:


Code: [Select]
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Button1.UseVisualStyleBackColor = False
        Button1.Text = Button1.BackColor.ToString 'or use Button1.BackColor.Name
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim cDialog As New ColorDialog()
        cDialog.Color = Button1.BackColor

        If (cDialog.ShowDialog() = DialogResult.OK) Then
            If Button1.BackColor <> cDialog.Color Then
                Button1.BackColor = cDialog.Color

                If (CInt(cDialog.Color.R) + CInt(cDialog.Color.G) + CInt(cDialog.Color.B)) > ((255I * 3I) \ 2I) Then
                    Button1.ForeColor = Color.Black
                Else
                    Button1.ForeColor = Color.White
                End If

                Button1.Text = cDialog.Color.ToString 'or use cDialog.Color.Name
            End If
        End If
    End Sub
« Last Edit: October 22, 2017, 08:10:46 PM by Godra »

Phrog30

  • Guest
Re: Color Picker
« Reply #3 on: April 12, 2018, 03:08:08 PM »
Thanks Godra.  I had a fancy combobox that was over complicated.  This works and is very simple.  I made a control with your sample code.

James

Phrog30

  • Guest
Re: Color Picker
« Reply #4 on: April 13, 2018, 12:39:11 PM »
Something I just noticed is a way to select web or system colors.  There is no way to select transparent with the color dialog.  Is there a way to call the 3-tab color dialog, which not only has the basic colors, but web and system colors as well?

James

Godra

  • Hero Member
  • *****
  • Posts: 1436
    • View Profile
Re: Color Picker
« Reply #5 on: April 13, 2018, 05:52:15 PM »
Maybe take a look at this project: https://www.codeproject.com/articles/14522/winforms-coloreditor-displayed-modeless

In the "Introduction" of that article, there are also links to these VB Net examples (one of which was actually posted by Archie in the first post):

https://www.codeproject.com/Articles/5306/The-ColorPicker-WinForms-Control

https://www.codeproject.com/Articles/8305/The-ColorPicker-WinForms-Control-Revisited

« Last Edit: April 13, 2018, 07:02:00 PM by Godra »

Phrog30

  • Guest
Re: Color Picker
« Reply #6 on: April 13, 2018, 06:03:02 PM »
Thank you sir