Paragraph indenting with TextBox

Ghost2
02-17-2005, 07:35 PM
When using a VB Code Window, you can select multiple lines, and then when you press tab (or shift + tab) the entire block is moved either to left or right by inserting a character (or a few) at the beginning of each line. How can I emulate this effect using only an ordinary TextBox?

passel
02-17-2005, 08:22 PM
Well, I would probably like to create my own using a picturebox.

But I guess as long as the lines don't wrap (all the lines are terminated by vbCrLF then
something like this could work.


Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim a As String, b As Long, c As Long
If KeyCode = vbKeyTab Then
If Text1.SelLength > 3 Then
If Shift = 0 Then
b = Text1.SelStart
a = Text1.SelText
a = " " & Replace(a, vbCrLf, vbCrLf & " ")
a = RTrim$(a)
c = Len(a)
Text1.SelText = a
Text1.SelStart = b
Text1.SelLength = c
ElseIf Shift = 1 Then
b = Text1.SelStart
a = Text1.SelText
If Left$(a, 2) = " " Then a = Mid$(a, 3)
a = Replace(a, vbCrLf & " ", vbCrLf)
c = Len(a)
Text1.SelText = a
Text1.SelStart = b
Text1.SelLength = c
End If
End If
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
If Text1.SelLength > 3 Then KeyAscii = 0
End If
End Sub


I was just going to do the shift right, and let you do the shift left as an exercise, but
I guess I'll do both but not add comments so you can add the comments explaining
what the code is doing for your exercise.

Ghost2
02-17-2005, 10:45 PM
Its ok, but theres a major bug. I switched the set of spaced with vbTab to get the effect I needed, but when I shift+tab, the top line doesn't outdent, but the others do. How can I fix this?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum