I have created the Colour Dialog as much as I can and have been told that might be helpful but everytime I try to use it in my program I have, which is a basic version of MS Paint, it crashes.

 Private Sub butCColor_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles butCColor.Click

        blnColorClicked = True

        Dim CColorD As New ColorDialog

        Me.BackColor = CColorD.Color

        CColorD.FullOpen = True

        CColorD.ShowHelp = False

        CColorD.AnyColor = True

        If (CColorD.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then

            cColor = CColorD.Color

            cColor = System.Drawing.Color.Black
        End If

    End Sub

This is the coding I have up. But to be honest, I have no idea what it does. It's borked and I have no idea how to fix it and need to work it out by the 17th of June. >< Please help?!

4 Years
Discussion Span
Last Post by Begginnerdev

What error messages do you receive? Also the error should point to a specific line. We'll need that as well.

Just from a perusal of your code, start with removing line 8, it's redudnant. Also is the scope of cColor global?

Edited by tinstaafl



After checking your code I found a fault that could causes the Crash.
"cColor" isn't declared in this part of your code!
Is it declared elsewhere?

Why you need this part of code:

blnColorClicked = True

Change this part:

If (CColorD.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then

            cColor = CColorD.Color ' change this into: Me.BackColor = CColorD.Color

            cColor = System.Drawing.Color.Black ' change this into:   Me.BackColor = Color.Black
        End If

Hope it helps,


You can try something like this:

'I think this is what you meant by cColor.
Private _CurrentColor As Color = Color.White

Public Property cColor As Color
        Return Me._CurrentColor
    End Get
    Set(value As Color)
        Me._CurrentColor = value
    End Set
End Property

As for the dialog code:

    'Create a new instance of the ColorDialog class.
    Dim cd As New ColorDialog

    'Set the dialog's properties.
    With cd
        'Dialog will have the custom color pane open automaticly.
        .FullOpen = True

        'Help button will NOT appear on the dialog.
        .ShowHelp = False

        'Ability to select any color.
        .AnyColor = True
    End With

    'If the user presses 'OK' set the Current Color and Background color of the current object.
    If cd.ShowDialog = Windows.Forms.DialogResult.OK Then
        cColor = cd.Color
        BackColor = cd.Color
        cColor = Color.Black
    End If
Catch ex As Exception
End Try
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.