Autore Topic: Visualizzare il testo in colori diversi all'interno di un ComboBox  (Letto 307 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.269
  • Ne mors quidem nos iunget
    • Mostra profilo
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.157
  • Tonno verde
    • Mostra profilo
Re:Visualizzare il testo in colori diversi all'interno di un ComboBox
« Risposta #1 il: 30 Luglio 2023, 15:48:50 »
Non so se qualcosa del genere potrebbe servire, altrimenti occorre creare un proprio componente, come ha fatto shordi qui:
https://gitlab.com/shordi/ComboSeek

Codice: [Seleziona]
Public Sub Form_Open()

  ''Buchungsbeispiele
   
   ComboBox4.Sorted = True
   ComboBox4.add(" ")
   ComboBox4.add(("Bezahlt Stromrechnung|Red"))
   ComboBox4.add(("Bezahlt Zeitschrift / Bücher|Red"))
   ComboBox4.add(("Bezahlt Königin|Red")) ' Etc...
   ' ComboBox4.add(("Bezahlt Hilfsmittel Königinenzucht"))
   ' ComboBox4.add(("Bezahlt Bienen"))
   ' ComboBox4.add(("Bezahlt Hilfsmittel Bienen"))
   ' ComboBox4.add(("Bezahlt Beute"))
   ' ComboBox4.add(("Bezahlt Rähmchen"))
   ' ComboBox4.add(("Bezahlt Beuten Zubehör"))
   ' ComboBox4.add(("Bezahlt Begattungk ästchen"))
   ' ComboBox4.add(("Bezahlt Futter "))
   ' ComboBox4.add(("Bezahlt Behandlung") & " TAMG")''
   ' ComboBox4.add(("Bezahlt Telefon"))
   ' ComboBox4.add(("Bezahlt Porto"))
   ' ComboBox4.add(("Bezahlt Verpackung"))
   ' ComboBox4.add(("Bezahlt Porto und Verpackung"))''
   ' ComboBox4.add(("Bezahlt Werkstatt Auto"))
   ' ComboBox4.add(("Bezahlt Miete Werkstatt"))
   ' ComboBox4.add(("Bezahlt Pacht Bienenstand"))
   ' ComboBox4.add(("Bezahlt Wasser"))
   ' ComboBox4.add(("Bezahlt Maschine"))
   ' ComboBox4.add(("Bezahlt Werkzeug Werkstatt"))
   ' ComboBox4.add(("Bezahlt Werkzeug Bienen"))
   ' ComboBox4.add(("Bezahlt Kleidung"))
   ' ComboBox4.add(("Bezahlt Werbung"))
   ' ComboBox4.add(("Bezahlt Honiggläser"))
   ' ComboBox4.add(("Bezahlt Etiketten"))
   ' ComboBox4.add(("Bezahlt BSV"))
   ' ComboBox4.add(("Bezahlt Labor"))
   ' ComboBox4.add(("Bezahlt Verein"))
   ' ComboBox4.add(("Bezahlt Berufsgenossenschaft"))
   ' ComboBox4.add(("Bezahlt Versicherungen"))
   ' ComboBox4.add(("Bezahlt Landwirtschaftskasse"))
   ' ComboBox4.add(("Bezahlt Gas"))
   ' ComboBox4.add(("Bezahlt Platzmiete Verkaufsstand"))
   ' ComboBox4.add(("Bezahlt Zubehör Honigproduktion"))
   ' ComboBox4.add(("Bezahlt Instandhaltung Gebäude"))
   ' ComboBox4.add(("Bezahlt Renovierung / Umbau Gebäude"))
   ' ComboBox4.add(("Bezahlt Privatentnahme"))
   ' ComboBox4.add(("Bezahlt sonstige Betriebsmittel"))
 
   'ComboBox4.Foreground = Color.Green
   ComboBox4.add(("Verkauf Privateinlage|Green"))
   ComboBox4.add(("Verkauf Honig") & " …|Green")
   ComboBox4.add(("Verkauf Honig 1 x 250 g Glas") & " …|Green")
   ' ComboBox4.add(("Verkauf Honig 1 X 500 g Glas") & " …")
   ComboBox4.add(("Verkauf Bienen|Green"))
   ' ComboBox4.add(("Verkauf Königin"))
   
End


Public Sub ComboBox4_Click()

  Dim iColor As Integer
  Dim s, sText, sColor As String = ComboBox4.Text
  Dim iPos As Integer = String.InStr(s, "|")

  sText = String.Mid(s, 1, iPos - 1)
  sColor = String.Mid(s, iPos + 1)
  If sColor = "Red" Then
    iColor = 16711680
  Else
    iColor = 32768 '65280
  Endif
  ComboBox4.Foreground = iColor
  ComboBox4.Text = sText

End
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.157
  • Tonno verde
    • Mostra profilo
Re:Visualizzare il testo in colori diversi all'interno di un ComboBox
« Risposta #2 il: 30 Luglio 2023, 17:47:28 »
Meglio ancora:

Codice: [Seleziona]
Public Sub Form_Open()

  ''Buchungsbeispiele
   
   ComboBox4.Sorted = True
   ComboBox4.add(" ")
   ComboBox4.add(("Bezahlt Stromrechnung"))
   ComboBox4.add(("Bezahlt Zeitschrift / Bücher"))
   ComboBox4.add(("Bezahlt Königin")) ' Etc...
   ComboBox4.add(("Bezahlt Hilfsmittel Königinenzucht"))
   ComboBox4.add(("Bezahlt Bienen"))
   ComboBox4.add(("Bezahlt Hilfsmittel Bienen"))
   ComboBox4.add(("Bezahlt Beute"))
   ComboBox4.add(("Bezahlt Rähmchen"))
   ComboBox4.add(("Bezahlt Beuten Zubehör"))
   ComboBox4.add(("Bezahlt Begattungk ästchen"))
   ComboBox4.add(("Bezahlt Futter "))
   ComboBox4.add(("Bezahlt Behandlung") & " TAMG")''
   ComboBox4.add(("Bezahlt Telefon"))
   ComboBox4.add(("Bezahlt Porto"))
   ComboBox4.add(("Bezahlt Verpackung"))
   ComboBox4.add(("Bezahlt Porto und Verpackung"))''
   ComboBox4.add(("Bezahlt Werkstatt Auto"))
   ComboBox4.add(("Bezahlt Miete Werkstatt"))
   ComboBox4.add(("Bezahlt Pacht Bienenstand"))
   ComboBox4.add(("Bezahlt Wasser"))
   ComboBox4.add(("Bezahlt Maschine"))
   ComboBox4.add(("Bezahlt Werkzeug Werkstatt"))
   ComboBox4.add(("Bezahlt Werkzeug Bienen"))
   ComboBox4.add(("Bezahlt Kleidung"))
   ComboBox4.add(("Bezahlt Werbung"))
   ComboBox4.add(("Bezahlt Honiggläser"))
   ComboBox4.add(("Bezahlt Etiketten"))
   ComboBox4.add(("Bezahlt BSV"))
   ComboBox4.add(("Bezahlt Labor"))
   ComboBox4.add(("Bezahlt Verein"))
   ComboBox4.add(("Bezahlt Berufsgenossenschaft"))
   ComboBox4.add(("Bezahlt Versicherungen"))
   ComboBox4.add(("Bezahlt Landwirtschaftskasse"))
   ComboBox4.add(("Bezahlt Gas"))
   ComboBox4.add(("Bezahlt Platzmiete Verkaufsstand"))
   ComboBox4.add(("Bezahlt Zubehör Honigproduktion"))
   ComboBox4.add(("Bezahlt Instandhaltung Gebäude"))
   ComboBox4.add(("Bezahlt Renovierung / Umbau Gebäude"))
   ComboBox4.add(("Bezahlt Privatentnahme"))
   ComboBox4.add(("Bezahlt sonstige Betriebsmittel"))
 
   'ComboBox4.Foreground = Color.Green
   ComboBox4.add((" Verkauf Privateinlage"))
   ComboBox4.add((" Verkauf Honig") & " …")
   ComboBox4.add((" Verkauf Honig 1 x 250 g Glas") & " …")
   ComboBox4.add((" Verkauf Honig 1 X 500 g Glas") & " …")
   ComboBox4.add((" Verkauf Bienen"))
   ComboBox4.add((" Verkauf Königin"))
   
End


Public Sub ComboBox4_Click()

  Dim iColor As Integer
  Dim sText As String = ComboBox4.Text

  If Left(sText) = " " Then
    iColor = 32768 '65280
  Else
    iColor = 16711680
  Endif
  ComboBox4.Foreground = iColor
  ComboBox4.Text = LTrim(sText)

End

Naturalmente occorre stare attenti quando si riceve i dati che questi siano puliti da eventuali spazi iniziali e aggiungere uno spazio solo al dato "verde"

Direi che può andare, cosa ne dici?
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro