1) par un bouton de commande : de sélectionner du texte (celui que tu veux)
2) par un autre bouton de commande : reprendre et continuer cette sélection en allant vers sa gauche
Tu as une Xème solution, c'est de passer par le format texte Rtf, mais bon la comme ça j'ai pas trop cherché en .net mais en vb6 ça m'a semblé logique...
Mais je ne dis pas que c'est impossible...
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question"dans les coulisses" pour tromper la dll
dépenser mon temps pour être à nouveau pigeon (et cela va venir, je le sais déjà depuis au moins 3 ans).
Option Explicit Private Type POINTAPI X As Long Y As Long End Type Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private mode As Byte Private chaine As String, longueur As Integer Private Sub Form_Load() chaine = "34567" RichTextBox1.Text = "aaaaa34567fffccc" longueur = calculelongueur() End Sub Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer) mode = 0 avancons RichTextBox1, "34567", Shift End Sub Private Sub RichTextBox1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then mode = 1 avancons RichTextBox1, chaine, 1 End If End Sub Private Sub avancons(RTB As RichTextBox, chaine As String, maj As Integer) Dim toto As String Static ou As Integer, pos As Integer If ou 0 Then ou RTB.SelStart: pos = InStr(RTB.Text, chaine) If maj = 1 Then Label1.Caption = RTB.SelText & vbCrLf & RTB.SelStart Select Case RTB.SelStart - ou Case 0 Dim ou1 As Integer ou1 = RTB.SelStart + RTB.SelLength If ou1 >= pos And ou1 < pos + Len(chaine) Then RTB.SelLength = RTB.SelLength + Len(chaine) - (ou1 - pos) - 1 End If Case Else On Error Resume Next toto = Mid(RTB.Text, RTB.SelStart - Len(chaine) + 2, Len(chaine)) On Error GoTo 0 If toto = chaine Then Select Case mode Case 0 Dim i As Integer For i = 1 To Len(chaine) - 1 SendKeys "{LEFT}" Next Case 1 Dim pa As POINTAPI GetCursorPos pa SetCursorPos pa.X - longueur, pa.Y End Select End If End Select ou = RTB.SelStart Else ou = 0 End If End Sub Private Function calculelongueur() As Integer With Me.Font .Name = RichTextBox1.Font.Name .Size = RichTextBox1.Font.Size .Bold = RichTextBox1.Font.Bold End With calculelongueur = TextWidth(Mid(chaine, 2)) End Function
Option Explicit Private Const texte As String = "34567" '----------------------------- 'Gestion de la sourie Private Const C_MouseEventF_LeftUp = &H4 Private Const C_MouseEventF_LeftDown = &H2 Private Const C_MouseEventF_Absolute = &H8000 Private Const Key_LMouseButton = 1 Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long Private Type KeyboardBytes kbByte(0 To 255) As Byte End Type Public Sub MouseRelacheGauche() mouse_event C_MouseEventF_LeftUp Or C_MouseEventF_Absolute, 0, 0, 0, 0 End Sub Public Sub MouseAppuisGauche() mouse_event C_MouseEventF_LeftDown Or C_MouseEventF_Absolute, 0, 0, 0, 0 End Sub Public Function ToucheEnfoncée(ByVal touche As Integer) As Boolean Dim KeyS As KeyboardBytes GetKeyboardState KeyS If KeyS.kbByte(touche) 128 Or KeyS.kbByte(touche) 129 Then ToucheEnfoncée = True Else ToucheEnfoncée = False End If End Function '----------------------------- Private Sub Form_Load() RichTextBox1.text = "aaaaa34567fff" End Sub Private Sub RichTextBox1_SelChange() Dim PositionDebutSelection As Integer Dim PositionFinSelection As Integer Dim PositionAMettreAJour As Boolean Static DebutSelection As Integer Static NouvelleSelection As Boolean Static SelectionDroiteGauche As Boolean Static NoRecursif As Boolean Debug.Print "- RichTextBox1_SelChange " & RichTextBox1.SelStart & " | " & RichTextBox1.SelLength If Not NoRecursif Then NoRecursif = True If RichTextBox1.SelLength = 0 Then SelectionDroiteGauche = False NouvelleSelection = True DebutSelection = RichTextBox1.SelStart ElseIf NouvelleSelection = True Then NouvelleSelection = False SelectionDroiteGauche = CBool(DebutSelection > RichTextBox1.SelStart) End If PositionDebutSelection = RichTextBox1.SelStart PositionFinSelection = RichTextBox1.SelStart + RichTextBox1.SelLength If InStr(RichTextBox1.text, texte) Then Dim PositionDebut34567 As Integer Dim PositionFin34567 As Integer PositionDebut34567 = InStr(RichTextBox1.text, texte) - 1 PositionFin34567 = PositionDebut34567 + Len(texte) If PositionDebutSelection > PositionDebut34567 And PositionDebutSelection < PositionFin34567 Then PositionDebutSelection = PositionDebut34567 PositionAMettreAJour = True End If If PositionFinSelection > PositionDebut34567 And PositionFinSelection < PositionFin34567 Then PositionFinSelection = PositionFin34567 PositionAMettreAJour = True End If End If If PositionAMettreAJour Then If SelectionDroiteGauche Then SelectionDeDroiteAGauche RichTextBox1, PositionDebutSelection, PositionFinSelection Else RichTextBox1.SelStart = PositionDebutSelection RichTextBox1.SelLength = PositionFinSelection - PositionDebutSelection End If End If NoRecursif = False End If End Sub Private Sub SelectionDeDroiteAGauche(ByRef RichTextBoxUtiliser As RichTextBox, ByVal PositionGauche As Integer, ByVal PostionDroite As Integer) Dim SourieGaucheAppuie As Boolean SourieGaucheAppuie = False If ToucheEnfoncée(Key_LMouseButton) Then MouseRelacheGauche DoEvents SourieGaucheAppuie = True End If RichTextBoxUtiliser.SelStart = PostionDroite RichTextBoxUtiliser.SelLength = 0 SendKeys "+{LEFT " & PostionDroite - PositionGauche & "}", True If SourieGaucheAppuie Then MouseAppuisGauche 'DoEvents End If End Sub
Private Sub Form_Load() Me.ScaleMode = vbPixels ' <<<<<<<<<<<<================ ici chaine = "34567" RichTextBox1.Text = "aaaaa34567fffccc" longueur = calculelongueur() End Sub
Private Function calculelongueur() As Integer With Me.Font .Name = RichTextBox1.Font.Name .Size = RichTextBox1.Font.Size .Bold = RichTextBox1.Font.Bold End With calculelongueur = TextWidth(Mid(chaine, 2)) calculelongueur = ScaleX(calculelongueur, Me.ScaleMode, vbPixels) ' <<<<======= ICI End Function
Dans une richtexbox composée d'une chaine A, d'une chaine X et d'une chaine B (dans cet ordre), je souhaite que toute sélection qui inclurait un ou plusieurs caractères de la chaîne X soit étendue pour englober la totalité de la chaîne X.
Et je souhaite que ce résultat soit obtenu quel que soit le sens (de gauche à droite ou de droite à gauche) de la sélection faite.
Non, si tu touches à selstart, tu ne pourras jamais plus "reprendre".