Selection of text in textbox on double click

drewsonian
01-22-2005, 06:14 PM
I'm writing a program to control an LED board in my office.

I have a textbox in which I use communication codes like <CLR RED> to indicate a change in color for a serial LED sign. After submitting the form, those codes are translated into the proper codes for the sign.

What I'd like to do is have the text box treat the <CLR RED> string as one unit. So, when a user clicks or double clicks in between the < > symbols, everything is highlighted from one symbol to the other. Right now double clicking especially messes with things, because it selects from space to space.

For example, when double clicking on "RED" in "<CLR RED>U99.5FM Radio", the textbox would automatically select from "RED" to the beginning of "Radio" instead of "<CLR RED>"

Any ideas?

Thanks! :)

webbone
01-22-2005, 06:41 PM
You could handle the double-click event so as to detect if the double-click occurred inside a tag and if so select the entire tag (overriding the default behaviour):

Private Sub Text1_DblClick()
Dim iCurPos As Integer, iFwdPos As Integer, iRevPos As Integer

Dim bFound As Boolean

iCurPos = Text1.SelStart + 1 'get the click location -SelStart is 0 based!

iFwdPos = InStr(iCurPos, Text1.Text, ">") 'find end of tag

If iFwdPos > 0 Then 'user clicked inside tag
iRevPos = InStrRev(Text1.Text, "<", iCurPos) 'find start of tag
If iRevPos > 0 Then 'found a whole tag
Text1.SelStart = iRevPos - 1 'SelStart is 0 based!
Text1.SelLength = iFwdPos - iRevPos + 1 'select entire tag
Else
'not in a tag, don't select anything
End If
End If


End Sub

drewsonian
01-22-2005, 07:21 PM
Thanks, that put me in the right direction and I've got it set.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum