Hi,
I have a GUI that writes a lot of information to a textbox.
I would like to be able to search for certain text and highlight/change its colour & jump to it in the 'results' textbox.
Ideally i would have a button and a textbox at the bottom of the form. The user enters the text they are looking for into the textbox and presses the button.
I have scroll bars on the results textbox but finding specific text at a later time can be difficult.
Pointers are welcome.
Geoff
Ability to Search for and highlight text in textbox?
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Ability to Search for and highlight text in textbox?
I recommend looking at the Text Box with Search form template. It offers some basic search functionality out of the box.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Ability to Search for and highlight text in textbox?
It is possible to do this with a RichTextBox. See: RichtTextBox Find
Re: Ability to Search for and highlight text in textbox?
Thanks both,
I have used a textbox in the GUI as i require the Copy & Paste right click context menu functionality.
There is no find method on a textbox.
I have used a textbox in the GUI as i require the Copy & Paste right click context menu functionality.
There is no find method on a textbox.
Re: Ability to Search for and highlight text in textbox?
Hi, Are you after something like this...
textbox1 contains your text
textbox2 contains the string you want to search for
when you click the buttonFindText the string will be highlighted in textbox1 and each subsequent click will move onto the next matched string.
$form1_Load = {
$textbox1.Select(0,0)
}
$buttonFindText_Click = {
$Content = $textbox1.Text
$keyword = $textbox2.Text
$IndexArray = @()
$first = $true
$Selected = $textbox1.SelectionStart
($content -split "$keyword") | %{
if ($first)
{
$len += $_.length
}
elseif ( { $len + $_.length + $keyword.length} -ne $Content.length )
{
$len += $_.length + $keyword.length
}
if ($len -ne $Content.length ){ $IndexArray += $len }
$first = $false
}
$textbox1.focus()
$textbox1.Select($IndexArray[0], $keyword.Length)
if ($Selected -eq 0)
{
$global:indexStart = 0
}
else
{
$global:indexStart++
}
$s = $IndexArray[$global:indexStart]
if (-not $s)
{
$global:indexStart = 0
return
}
$textbox1.focus()
$textbox1.Select($IndexArray[$global:indexStart], $keyword.Length)
}
textbox1 contains your text
textbox2 contains the string you want to search for
when you click the buttonFindText the string will be highlighted in textbox1 and each subsequent click will move onto the next matched string.
$form1_Load = {
$textbox1.Select(0,0)
}
$buttonFindText_Click = {
$Content = $textbox1.Text
$keyword = $textbox2.Text
$IndexArray = @()
$first = $true
$Selected = $textbox1.SelectionStart
($content -split "$keyword") | %{
if ($first)
{
$len += $_.length
}
elseif ( { $len + $_.length + $keyword.length} -ne $Content.length )
{
$len += $_.length + $keyword.length
}
if ($len -ne $Content.length ){ $IndexArray += $len }
$first = $false
}
$textbox1.focus()
$textbox1.Select($IndexArray[0], $keyword.Length)
if ($Selected -eq 0)
{
$global:indexStart = 0
}
else
{
$global:indexStart++
}
$s = $IndexArray[$global:indexStart]
if (-not $s)
{
$global:indexStart = 0
return
}
$textbox1.focus()
$textbox1.Select($IndexArray[$global:indexStart], $keyword.Length)
}