Results 1 to 3 of 3

Thread: Foreground / Backgroud colors for disabled combobox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342

    Foreground / Backgroud colors for disabled combobox

    How do you change the foreground and background colors of a disabled combo box? It is using the Windows default colors when I disable it.

    I tried using DrawMode=OwnerDraw and specifying my colors in the DrawItem event but the system seems to ingoring the event.

    Thanks!!

  2. #2
    New Member
    Join Date
    Apr 2004
    Posts
    12

    try this out....

    Ok I did this 2 different ways (assumes cbobox is already disabled). The first will when a button is clicked bring up a dialog box with colors to pick from. Whatever color you pick the background color will change to that color.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click

    'create ColorDialog object
    Dim colorBox As ColorDialog = New ColorDialog()
    Dim result As DialogResult

    'show ColorDialog and get result
    result = colorBox.ShowDialog()

    If result = DialogResult.Cancel Then
    Return
    End If

    ' set background color to color picked from dialog
    cboObj.ForeColor = colorBox.Color
    cboObj.BackColor = colorBox.Color

    End Sub

    The second way is without a color dialog box being displayed.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click

    cboObj.BackColor = Color.Red

    End Sub

    The only problem is the cbobox being disabled. Reason is b/c since it is disabled it will only put a boarder aroung the interior of the cbobox and I don't think that is what you are going for. What you could do is leave the box enabled and set it to, when it is clicked change focus to another object.

    Private Sub cboObj_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboObj.Click

    'determines if the cbobox should be active, if not changes focus to something else
    If strON = "F" Then
    cboObj.BackColor = Color.Red
    btnChange.Focus()
    End If

    End Sub

    With this approach you can set the variable strON to something else when you want the cbobox to be active and vice versa. This is just a thought since I am not sure what you are trying to do.

    Hope this helps!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    Thank you for the time you took writing that.

    Your approach is pretty much what I have decided I am going to have to do. I was hoping there was a way of simply disabling it instead of just a work around. Seems to me that this would be a common problem, I can't beleive Microsoft hasn't addressed it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width