Locked Color Dialog does not work.

  • Thursday, August 30, 2012 2:57 PM
     
     

    So I get this error:

    Reference to a non-shared Member requires an object reference.

    The code is this:

    Private Sub colorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles colorButton.Click
            ColorDialog.Color = Me.BackColor
            ColorDialog.ShowDialog()
            Me.BackColor = Color.Dialog.Color
        End Sub

    I don't know what to do, and I really need the help. I just started programming and I can't finish the project due to this error.


All Replies

  • Thursday, August 30, 2012 3:05 PM
     
     Answered Has Code

    hi,

    try this:

    Private Sub colorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles colorButton.Click
    using dlg as new ColorDialog
        dlg.Color = Me.BackColor
        if dlg.ShowDialog() = dialogresult.ok then
            Me.BackColor = dlg.Color
        end if
    end using
    End Sub


    Regards, Nico

    • Marked As Answer by Markus_Lacey Thursday, August 30, 2012 3:11 PM
    •  
  • Thursday, August 30, 2012 3:10 PM
     
     

    Thank you. It works, you saved me.