vb.netcolordialog

vb.net creating a square to show a color selected by a color dialog


I want to have a little square that will display the color currently selected by a color dialog.

It should look like this: Picture of what I want

And the green box, should update to another color when they choose one. How would I go about doing this?


Solution

  • Using colorDialog As New ColorDialog
        'If the user actually selected a color Then
        If colorDialog.ShowDialog() = DialogResult.OK Then
            'Set the background color of the picture box = color selected from the color dialog
            PictureBox1.BackColor = colorDialog.Color
        End If
    End Using
    

    Place this code in your Button_Click event handler.