20/05/20 9:07
aragorn76
Eccomi son tornato... alla fine ho cambiato metodo perchè con le doppie \ mi segnava come hyperlink (e quindi cliccabile) ma nel metterlo in un db mysql e poi riprendere la stringa, mi faceva diventare tutto come un unico link... quindi ho ovviato con il colore, sfruttando la tua idea e trovando uno script carino
cosi facendo, appena si digita < nella richtextbox si apre il form e in base alla scelta, fa terminare la parola con altro segno che viene riconosciuto e poi vi è il controllo il ciclo do until, loop che colora... tutto funziona.. cosi facendo i nomi risultano blu e cognomi rossi.. poi mi prendo i valori pulendo la richtextbox dai caratteri < > e |.....
adesso il poblema è... se tali nomi li ho inseriti in una tabella e quando riprendo i valori mi accorgo che un nome è sbagliato.. vorrei cliccarci sopra per modificarlo.. ma non so se possibile cliccare su una parola colorata e in base al colore prendere il valore, in modo che poi lo modifico anche nella tabella nomi... adesso vedo ma se avete idee o metodo che potrei usare, li accetto volentieri
' preparazione form di input ' meglio fare in progettazione complesso quanto vuoi Formdentro.Text = "Inserisci" Formdentro.Size = New Size(200, 180) Formdentro.ControlBox = False Formdentro.Location = New Point(20000, 15000) ' preparazione text su form di input TextInput.Location = New Point(10, 10) TextInput.Size = New Point(150, 20) TextInput.CharacterCasing = CharacterCasing.Upper Formdentro.Controls.Add(TextInput) ' preparazione button su form di input Inserisci.Text = "Inserisci" Inserisci.Location = New Point(100, 80) Inserisci.TabIndex = 3 Formdentro.Controls.Add(Inserisci) AddHandler Inserisci.Click, AddressOf Inserisci_OnClick ' permette di avere l'evento click ' preparazione button su form di input Annulla.Text = "Annulla" Annulla.Location = New Point(100, 110) Annulla.TabIndex = 3 Formdentro.Controls.Add(Annulla) AddHandler Annulla.Click, AddressOf Annulla_OnClick ' permette di annullare ' preparazione radiobutton su form di input For i = 0 To 1 Scelta(i) = New RadioButton Scelta(i).Location = New Point(10, 24 * i + 40) Formdentro.Controls.Add(Scelta(i)) Next Scelta(0).Checked = True Scelta(0).Text = "Nome " Scelta(0).TabIndex = 1 Scelta(1).Text = "Cognome " Scelta(1).TabIndex = 2
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged If pos1 > RichTextBox1.TextLength Then pos1 = RichTextBox1.TextLength Dim pos As Integer = RichTextBox1.Text.IndexOf("<", pos1) If pos <> -1 Then pos1 = pos + 2 : FormInput.Show() End Sub
Private Sub Inserisci_OnClick(sender As Object, e As EventArgs) If Scelta(0).Checked = True Then RichTextBox1.Text = RichTextBox1.Text & TextInput.Text & "> " Else RichTextBox1.Text = RichTextBox1.Text & TextInput.Text & "| " End If TextInput.Text = "" Formdentro.Hide() RichTextBox1.Focus() '\\\\\\\\\\\\\\\\ 'codice per il colore Dim SearchTerm As String = "<" Dim ResultIndex As Integer = Nothing Dim SearchStartIndex As Integer = 0 'Loop until the searchword is not found in the RichTextBox Do Until ResultIndex = -1 'Progressive search (search from the end of the last result) ResultIndex = RichTextBox1.Text.IndexOf(SearchTerm, SearchStartIndex) 'If the searchstring was not found then cancel the routine If ResultIndex = -1 Then Exit Do 'Get the line the matched string occurs on (narrows things down a bit) Dim ResultLine As Integer = RichTextBox1.GetLineFromCharIndex(ResultIndex) Dim ResultLineStart As Integer = RichTextBox1.GetFirstCharIndexFromLine(ResultLine) Dim GetWordStart As Integer = ResultLineStart 'Loop backwards from the Index where the match begins to the beginning of the line For i As Integer = ResultIndex To ResultLineStart Step -1 'Record the position following a space (" "). If RichTextBox1.Text.Chars(i) = " " Then GetWordStart = i + 1 Exit For End If Next i 'Loop through and find the end of the current Word (index before the next space in the line) Dim GetWordEnd As Integer = RichTextBox1.TextLength - 1 For i As Integer = ResultIndex To GetWordEnd If RichTextBox1.Text.Chars(i) = " " Then GetWordEnd = i Exit For End If Next 'This is the Full 'word' that contains the searchstring Dim GetFullWord As String = RichTextBox1.Text.Substring(GetWordStart, GetWordEnd - GetWordStart).Trim 'If it starts with a link syntax then select and highlight the text If GetFullWord.EndsWith(">") Then RichTextBox1.Select(GetWordStart, GetWordEnd - GetWordStart) RichTextBox1.SelectionColor = Color.LightBlue RichTextBox1.Select(RichTextBox1.TextLength, 0) End If If GetFullWord.EndsWith("|") Then RichTextBox1.Select(GetWordStart, GetWordEnd - GetWordStart) RichTextBox1.SelectionColor = Color.LightCoral RichTextBox1.Select(RichTextBox1.TextLength, 0) End If 'Update the start index for the search to begin from on the next pass, or cancel further searches if we are at the end of the string If GetWordEnd = RichTextBox1.TextLength - 1 Then Exit Do Else SearchStartIndex = ResultIndex + 1 Loop End Sub
cosi facendo, appena si digita < nella richtextbox si apre il form e in base alla scelta, fa terminare la parola con altro segno che viene riconosciuto e poi vi è il controllo il ciclo do until, loop che colora... tutto funziona.. cosi facendo i nomi risultano blu e cognomi rossi.. poi mi prendo i valori pulendo la richtextbox dai caratteri < > e |.....
adesso il poblema è... se tali nomi li ho inseriti in una tabella e quando riprendo i valori mi accorgo che un nome è sbagliato.. vorrei cliccarci sopra per modificarlo.. ma non so se possibile cliccare su una parola colorata e in base al colore prendere il valore, in modo che poi lo modifico anche nella tabella nomi... adesso vedo ma se avete idee o metodo che potrei usare, li accetto volentieri
Ultima modifica effettuata da aragorn76 20/05/20 9:08
aaa