Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2016
    Messaggi
    18

    Modificare testo in richtext box

    Sono riuscito a scrivere questo piccolo programmino che mi cambia il colore del testo a seconda dei parametri inseriti e funziona bene:


    For CONTA = contatore To lunghezza - 1 Step 1










    If X(CONTA) = "N" Then
    K = "N"
    COLORE = Color.Gray


    End If
    If X(CONTA) = "X" Then
    K = "X"
    COLORE = Color.Blue
    End If
    If X(CONTA) = "Y" Then
    K = "Y"
    COLORE = Color.Red
    End If
    If X(CONTA) = "Z" Then
    K = "Z"
    COLORE = Color.Maroon
    End If
    If X(CONTA) = "S" Then
    K = "S"
    COLORE = Color.Blue
    End If
    If X(CONTA) = "T" Then
    K = "T"
    COLORE = Color.White
    End If
    If X(CONTA) = "M" Then
    K = "M"
    COLORE = Color.Brown
    End If
    If X(CONTA) = "G" Then
    K = "G"
    COLORE = Color.White
    End If
    If X(CONTA) = "F" Then
    K = "F"
    COLORE = Color.Orange
    End If
    Select Case X(CONTA)








    Case K




    Select Case X(CONTA + 1)
    'PRIMA CIFRA
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "12".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)








    'SECONDA CIFRA
    Select Case X(CONTA + 2)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "123".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)


    Select Case X(CONTA + 3)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "1234".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 4)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "12345".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 5)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "123456".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 6)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "1234567".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 7)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "12345678".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 8)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "123456789".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 9)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "1234567890".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 10)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "12345678901".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 11)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "123456789012".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    Select Case X(CONTA + 12)
    Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "."
    RichTextBox1.Select(CONTA, "1234567890123".Length)
    RichTextBox1.Focus()
    RichTextBox1.SelectionColor = COLORE
    RichTextBox1.Select(RichTextBox1.Text.Length, 0)
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    End Select
    quello che non riesco a fare sono le eccezioni.
    mi spiego meglio:
    vorrei che se mettessi un testo nelle parentesi() esso dia sempre di un colore definito,tipo verde,anche le parentesi dello stesso colore. come posso implementare il codice?
    ringrazio in anticipo chi volesse dare un aiutino.

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Il codice è già contorto ed inutilmente lungo ... se non usi i tag CODE del forum non si capisce nulla.
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Fai un overload della RichTextBox.

    codice:
       <System.Runtime.CompilerServices.Extension()> _    
        Public Sub AppendText(box As RichTextBox, text As String, color As Color)
    
            box.SelectionStart = box.TextLength
            box.SelectionLength = 0
            box.SelectionColor = color
            box.AppendText(text)
            box.SelectionColor = box.ForeColor
    
    
        End Sub

    Ed aggiungi in successione testo, singole lettere, parentesi col colore che vuoi con un semplice:

    RichTextBox1.AppendText(Testo, Colore)

    Mi pare un attimino più semplice.
    Ultima modifica di eziogsv; 18-04-2016 a 01:04

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2016
    Messaggi
    18
    Inn atti. Grazie. È solo da qualche settimana che programmo.sto imparando. Grazie ancora

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.