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

        CColorD.ShowDialog()
        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
        Else

            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?!

Recommended Answers

All 3 Replies

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?

Hi,

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
        Else

            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
    Get
        Return Me._CurrentColor
    End Get
    Set(value As Color)
        Me._CurrentColor = value
    End Set
End Property

As for the dialog code:

Try
    '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
    Else
        cColor = Color.Black
    End If
Catch ex As Exception
    MsgBox(ex.ToString)
End Try
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.