ColorDialog

bjwade62

Centurion
Joined
Oct 31, 2003
Messages
104
I have the following code in a click event. It's supposed to change the bachground color of a listview control. It works fine except when I click the cancel button in the ColorDialog control. When I do that it sets the listview color to black. Any help out there? Thanks!

ColorDialog1.ShowDialog()
lblLeftSide.BackColor = ColorDialog1.Color
frmMain.lvwLeftList.BackColor = ColorDialog1.Color
 
You need to check how the user exits the ColorDialog form. Basically the following code says if the user didn't click cancel then change colours. You could also change this to say if the user did click ok by changing it to == DialogResult.Ok.
Visual Basic:
        If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
            lblLeftSide.BackColor = ColorDialog1.Color
            frmMain.lvwLeftList.BackColor = ColorDialog1.Color
        End If
 
That works but I have to hit cancel twice to completely dismiss the colordialog box.

Cags said:
You need to check how the user exits the ColorDialog form. Basically the following code says if the user didn't click cancel then change colours. You could also change this to say if the user did click ok by changing it to == DialogResult.Ok.
Visual Basic:
        If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
            lblLeftSide.BackColor = ColorDialog1.Color
            frmMain.lvwLeftList.BackColor = ColorDialog1.Color
        End If
 
I suspect thats because you did something like this....
Visual Basic:
        ColorDialog1.ShowDialog() 
        If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
            lblLeftSide.BackColor = ColorDialog1.Color
            frmMain.lvwLeftList.BackColor = ColorDialog1.Color
        End If
The line
Visual Basic:
If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
displays the dialog and checks the result so you don't have to call it seperately from that line of code.
 
I was just about to tell you I fixed it. That's exactly what I had. Man I hope to be as good as you someday! Thanks Again!

Cags said:
I suspect thats because you did something like this....
Visual Basic:
        ColorDialog1.ShowDialog() 
        If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
            lblLeftSide.BackColor = ColorDialog1.Color
            frmMain.lvwLeftList.BackColor = ColorDialog1.Color
        End If
The line
Visual Basic:
If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
displays the dialog and checks the result so you don't have to call it seperately from that line of code.
 
Back
Top