Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

       If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
           lblLeftSide.BackColor = ColorDialog1.Color
           frmMain.lvwLeftList.BackColor = ColorDialog1.Color
       End If

Anybody looking for a graduate programmer (Midlands, England)?
Posted

That works but I have to hit cancel twice to completely dismiss the colordialog box.

 

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.

       If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
           lblLeftSide.BackColor = ColorDialog1.Color
           frmMain.lvwLeftList.BackColor = ColorDialog1.Color
       End If

Posted

I suspect thats because you did something like this....

       ColorDialog1.ShowDialog() 
       If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
           lblLeftSide.BackColor = ColorDialog1.Color
           frmMain.lvwLeftList.BackColor = ColorDialog1.Color
       End If 

The line

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.

Anybody looking for a graduate programmer (Midlands, England)?
Posted

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!

 

I suspect thats because you did something like this....

       ColorDialog1.ShowDialog() 
       If ColorDialog1.ShowDialog() <> DialogResult.Cancel Then
           lblLeftSide.BackColor = ColorDialog1.Color
           frmMain.lvwLeftList.BackColor = ColorDialog1.Color
       End If 

The line

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...