Searching a textbox

F

fniles

I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when it
finds the text, move my cursor in the textbox to where the found text is.
How can I do that ?
Thank you
 
K

kimiraikkonen

I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when it
finds the text, move my cursor in the textbox to where the found text is.
How can I do that ?
Thank you

Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel
 
F

fniles

Thank you.
If the found text is on page 2, how do I move my scroll bar so that it will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st page,
not until I page down to the 2nd page I will see the highlighted text.

Thanks

I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when
it
finds the text, move my cursor in the textbox to where the found text is.
How can I do that ?
Thank you

Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel
 
K

kimiraikkonen

Thank you.
If the found text is on page 2, how do I move my scroll bar so that it will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st page,
not until I page down to the 2nd page I will see the highlighted text.

Thanks




Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel

You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel
 
F

fniles

Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?

Thank you.

Thank you.
If the found text is on page 2, how do I move my scroll bar so that it
will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st page,
not until I page down to the 2nd page I will see the highlighted text.

Thanks




Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel

You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel
 
T

Teemu

fniles said:
Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?

TextBox1.ScrollToCaret() will do the trick.

-Teemu
 
K

kimiraikkonen

Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?

Thank you.










You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel

Now i hope i understood, you're talking about one and the same textbox
control which is structured by your own as pages, so you want your
unique textbox to be scrolled when and where the text is found?

So, i've found ScrollToCaret method which should do what you want, so
the extended code will look like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
' Go to selectedtext piece and scrool
TextBox1.ScrollToCaret()
End Sub

Hope this helps, let us know...

Thanks,

Onur Güzel
 
F

fniles

Thank you very much for your help.
That's what I was looking for.

Thanks again

Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?

Thank you.










You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel

Now i hope i understood, you're talking about one and the same textbox
control which is structured by your own as pages, so you want your
unique textbox to be scrolled when and where the text is found?

So, i've found ScrollToCaret method which should do what you want, so
the extended code will look like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
' Go to selectedtext piece and scrool
TextBox1.ScrollToCaret()
End Sub

Hope this helps, let us know...

Thanks,

Onur Güzel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top