AdvancedHMI Software
General Category => Additional Components => Topic started by: Archie on September 16, 2017, 02:52:50 PM
-
This is a color picker that uses the same picker used by the properties window.
-
Thanks Archie...
-
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:
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
-
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
-
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
-
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
-
Thank you sir