1: come si esegue la tabulazione del testo in una RichTextBox?
Zampa (tab) fa (tab) domande (tab) stupide
2: come modifico la dimensione di una parola in una stringa di testo?
esempio:
Zampa fa domande stupide
grazie
1: come si esegue la tabulazione del testo in una RichTextBox?
Zampa (tab) fa (tab) domande (tab) stupide
2: come modifico la dimensione di una parola in una stringa di testo?
esempio:
Zampa fa domande stupide
grazie
Hey hey, my my Rock and roll can never die!
Per la tabulazione:
Option Explicit
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
Dim strLinea As String
Dim lngPos As Long
Dim intX As Integer
Dim strChar As String
Dim strPreLine As String
Dim lngMyPosition As Long
Dim strRTBText As String
'Se viene premuto il tasto enter...
If KeyAscii = vbKeyReturn Then
If RichTextBox1.SelStart = 0 Then Exit Sub
'Salvo la posizione del cursore
lngMyPosition = RichTextBox1.SelStart
'Rilevo l'ultima (precedente) posizione di un CR+LF
lngPos = InStrRev(RichTextBox1.Text, vbCrLf, RichTextBox1.SelStart)
If lngPos = 0 Then
lngPos = 1
Else
lngPos = lngPos + 2
End If
'Ottengo la linea di testo relativa alla riga in cui ho premuto il tasto enter
strLinea = Mid(RichTextBox1.Text, lngPos, (RichTextBox1.SelStart - lngPos) + 1)
'Ciclo sulla riga finche' non trovo un carattere diverso
'da uno spazio o da una tabulazione
For intX = 1 To Len(strLinea)
'Prelevo un carattere dalla linea di testo
strChar = Mid(strLinea, intX, 1)
Select Case strChar
'Se e' uno spazio, lo concateno in strPreLine
Case Is = " "
strPreLine = strPreLine & strChar
'Se e' una tabulazione, la concateno in strPreLine
Case Is = vbTab
strPreLine = strPreLine & strChar
'Ok, ho trovato un carattere valido, quindi esco dal ciclo
Case Else
Exit For
End Select
Next
'Se c'e' quindi un 'PreLine'...
If Len(strPreLine) > 0 Then
'...per evitare il flickering della RTB
LockWindowUpdate RichTextBox1.hWnd
'Memorizzo il testo dell'RTB
strRTBText = RichTextBox1.Text
'Inserisco il nuovo testo
RichTextBox1.Text = Left(strRTBText, lngMyPosition) & vbCrLf & strPreLine & Mid(strRTBText, lngMyPosition + 1)
'Posiziono il cursore
RichTextBox1.SelStart = Len(Left(strRTBText, lngMyPosition) & vbCrLf & strPreLine)
'Disattivo il KeyPress
KeyAscii = 0
LockWindowUpdate False
End If
End If
End Sub'Disattivo il KeyPress
per la selezione del testo tutte le proprietà che iniziano con "sel"
per la tabulazione ho risolto salvando in una variabile la lunghezza della parola < Lan(testo) > e utilizzando la funzione Space(i) < Space(i - Lan(testo)) >
Hey hey, my my Rock and roll can never die!