none
ComboBox forecolor after select RRS feed

  • Question

  • hi

    Use CompBox to create an entry click here
    So that the user knows how to work
    When I want to use the added click here and have a gray color
    When leaving the cambo box is not empty
    And also not selected Click here to be black color

      Private Sub COMBO_BOX_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles COMBO_BOX.Enter
                   Me.COMBO_BOX.Items.Remove("CLICK HERE")
            Me.COMBO_BOX.ForeColor = Color.Black
        End Sub
    
        Private Sub COMBO_BOX_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles COMBO_BOX.LostFocus
           
            If COMBO_BOX.SelectedItem = Nothing Then
                Me.COMBO_BOX.Items.Insert(0, "CLICK HERE")
                Me.COMBO_BOX.SelectedItem = "CLICK HERE"
                Me.COMBO_BOX.ForeColor = Color.LightGray
            ElseIf COMBO_BOX.SelectedItem = "CLICK HERE" Then
                Me.COMBO_BOX.ForeColor = Color.LightGray
            Else
                Me.COMBO_BOX.ForeColor = Color.Black
            End If
        End Sub
    
        Private Sub COMBO_BOX_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COMBO_BOX.SelectedIndexChanged
           
            If COMBO_BOX.SelectedItem = Nothing AndAlso COMBO_BOX.SelectedItem = "CLICK HERE" Then
                Me.COMBO_BOX.ForeColor = Color.LightGray
            Else
                Me.COMBO_BOX.ForeColor = Color.Black
            End If
        End Sub


    • Edited by ahmeddc Thursday, December 6, 2018 2:39 AM
    Thursday, December 6, 2018 2:22 AM

Answers

  • Hi,

    I am not quite sure what you want,but the code is wrong.

       If COMBO_BOX.SelectedItem = Nothing AndAlso COMBO_BOX.SelectedItem = "CLICK HERE"

    my code:

    Public Class Form1
        Private Sub COMBO_BOX_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles COMBO_BOX.Enter
            Me.COMBO_BOX.Text = ""
            Me.COMBO_BOX.ForeColor = Color.Black
        End Sub
    
        Private Sub COMBO_BOX_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles COMBO_BOX.LostFocus
    
            Me.COMBO_BOX.Text = "CLICK HERE"
            Me.COMBO_BOX.ForeColor = Color.LightGray
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.COMBO_BOX.Text = "CLICK HERE"
            Me.COMBO_BOX.ForeColor = Color.LightGray
        End Sub
    
        Private Sub COMBO_BOX_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
    
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Thursday, December 6, 2018 5:53 AM
    Thursday, December 6, 2018 5:23 AM

All replies

  • Hi,

    I am not quite sure what you want,but the code is wrong.

       If COMBO_BOX.SelectedItem = Nothing AndAlso COMBO_BOX.SelectedItem = "CLICK HERE"

    my code:

    Public Class Form1
        Private Sub COMBO_BOX_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles COMBO_BOX.Enter
            Me.COMBO_BOX.Text = ""
            Me.COMBO_BOX.ForeColor = Color.Black
        End Sub
    
        Private Sub COMBO_BOX_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles COMBO_BOX.LostFocus
    
            Me.COMBO_BOX.Text = "CLICK HERE"
            Me.COMBO_BOX.ForeColor = Color.LightGray
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.COMBO_BOX.Text = "CLICK HERE"
            Me.COMBO_BOX.ForeColor = Color.LightGray
        End Sub
    
        Private Sub COMBO_BOX_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
    
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Thursday, December 6, 2018 5:53 AM
    Thursday, December 6, 2018 5:23 AM
  • thanks
    Thursday, December 6, 2018 5:54 AM