關於VB combobox items?

請問items中

若選項有1 2 3 4 5

想把 4 5 forecolor設為其他顏色

應該如何設定

1 個解答

評分
  • John
    Lv 7
    2 年前
    最佳解答

    一定要將DrawMode改為OwnerDrawVariable才有效

    Private Sub ComboBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox1.DrawItem

    Dim currentText As String = ComboBox1.Items(e.Index).ToString

    Dim textColour As System.Drawing.Color = Color.Black

    If "4" = currentText Or "5" = currentText Then

    textColour = Color.Red

    End If

    e.Graphics.DrawString(currentText, e.Font, New SolidBrush(textColour), e.Bounds)

    End Sub

還有問題?馬上發問,尋求解答。