-
Feb 24th, 2016, 04:58 PM
#1
Thread Starter
Addicted Member
TextBox selection problem
I'm developing an app for Windows Phone 8.1 and having problem to select text correctly. There is a MultiLine TextBox when i search for word, i highlight it, the problem is that, highlighting works perfect if the word is in first line but if it is in the second line, the highlight shifted to left one character and if it is in the third line, the highlight shifted to left two characters
EX:
if TextBox text is
Code:
aaa-aaa-
aaa-aaa-
aaa-aaa-
and search for "aaa", tapping on Find Next button produce the following highlighting sequence
Code:
aaa-aaa-
aaa-aaa-
aaa-aaa-
Code:
aaa-aaa-
aaa-aaa-
aaa-aaa-
Code:
aaa-aaa-
aaa-aaa-
aaa-aaa-
Code:
aaa-aaa-
aaa-aaa-
aaa-aaa-
As you can see, the highlighting continue shift to the right for each new line
Here is my code
Code:
Private mstrSearch As String = "aaa"
Private mintIndex As Integer = -1
Private Sub btnSearch_Click(sender As Object, e As RoutedEventArgs)
mintIndex = txtMain.IndexOf(mstrSearch, mintIndex + 1)
If mintIndex >= 0 Then
txtMain.Focus(FocusState.Programmatic)
txtMain.SelectionStart = mintIndex
txtMain.SelectionLength = mstrSearch.Length
End If
End Sub
Last edited by Absolute_Zero; Feb 24th, 2016 at 05:23 PM.
On Error GoTo Hell
-
Apr 3rd, 2019, 11:45 AM
#2
New Member
Re: TextBox selection problem
I was not able to make that technique work because the user needs to be able to work with the TextBox as a normal text box. That is to say, they need to be able to select and edit portions of the text. If I hook the click event, then the user cannot select any text to edit it.
I was trying to use the Enter event so that it would only select all of the text the first time that the user clicked on it. If the user then works with the text (clicking to select a portion of the text to edit), I don't want to reselect the entire text.
I found that this seemed to work for me:
Private Sub SelectionTextBox_Enter(sender As Object, e As System.EventArgs) Handles SelectionTextBox.Enter
Dim tb = TryCast(SelectionTextBox.TextBoxElement.TextBoxItem.HostedControl, TextBox)
tb.BeginInvoke(New MethodInvoker(Sub() tb.SelectAll()))
-
Oct 5th, 2019, 11:17 AM
#3
Hyperactive Member
Re: TextBox selection problem
@amzoun95 - post relevant code with code tags in order to improve readability.
-
Nov 13th, 2019, 09:19 AM
#4
Re: TextBox selection problem
Hello,
For me, this correction works :
Code:
public mstrSearch As String = "aaa"
public mintIndex As Integer = -1
Private Sub btnSearch_Click(sender As Object, e As RoutedEventArgs)
mintIndex = txtMain.text.IndexOf(mstrSearch, mintIndex + 1) 'here I added .text as indexof in not a method of textbox but of text
If mintIndex >= 0 Then
txtMain.Focus() 'I removed FocusState.Programmatic as I don't have the UI.XAML library installed but it just show block instead of coloring the letters
txtMain.SelectionStart = mintIndex
txtMain.SelectionLength = mstrSearch.Length
End If
End Sub
result after 6 clicks :
Regards
Last edited by Delaney; Nov 13th, 2019 at 09:26 AM.
Reason: added picture of result
-
Feb 3rd, 2020, 05:42 AM
#5
Banned
Re: TextBox selection problem
I have seen other questions for this and none of them have sufficient answers. With the 2018 update, I now have alot of trouble with text selection.
If I were to take a stab at specifying the case, here it is. When I am editing text and I have a text box in scope, I am accustomed to being able to easily marquee select text for highlighting / editing (in 2017 and prior). Now, with 2018, it often creates a NEW text element when I try to marquee select text I am editing. I believe that in the past, I could start a Marquee selection with my mouse outside the bounds of the text box. But in 2018, that will now create a new text box. So I must be extremely precise with the marquee selection start point, at Illustrator is very finicky about it. In fact it requires not only that I be within the the text box - but that my cursor is actually over text IN the box at the time the marquee selection starts. This is very limiting, as it is virtually impossible to group select the exact text you want as you only have about a pixel or two beyond the last character before the cursor is considered out of scope.
Looks like alot of other people have had this problem, and yes I have tried checking Preferences-> Type and "type Objection Selection by Path Only" is not checked. And checking it makes it even harder to select text.
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|