473,411 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Highlighting text

jamesd0142
469 256MB
Is there a way to highlight text in a vb textbox?

For example i have a string, "my name is James"

I search for "name" it finds it in the string and now i want to highlight that part of the string in the text box.

Thanks
Nov 1 '07 #1
4 1324
QVeen72
1,445 Expert 1GB
Hi,

Yes, you can.. but For TextBox, the Selected Item will be shown only if the TextBox has the Focus..
This code will allow you to Select the Text:

Expand|Select|Wrap|Line Numbers
  1. Dim TStr As String
  2. Dim i As Integer
  3. TStr = "Veena"
  4. i = InStr(Text1.Text, TStr)
  5. If i >= 0 Then
  6.     If i > 0 Then
  7.        Text1.SelStart = i - 1
  8.     Else
  9.         Text1.Text = 0
  10.     End If
  11.     Text1.SelLength = Len(TStr)
  12. End If
  13.  
  14.  
Regards
Veena
Nov 1 '07 #2
jamesd0142
469 256MB
ok i understand the logic of this code, thanks...

but, it doesnt highlight the text in the text box.

please look at the image,
i want it to look like this when i search for 'James'

im using vb express edition 2005
[IMG]
Nov 1 '07 #3
Killer42
8,435 Expert 8TB
but For TextBox, the Selected Item will be shown only if the TextBox has the Focus..
That is only true if the HideSelection property is True.
Nov 2 '07 #4
Killer42
8,435 Expert 8TB
ok i understand the logic of this code, thanks...

but, it doesnt highlight the text in the text box.
The point is to set the .SelStart and .SelLength properties to select the relevant part of the text. That's in VB6, though - may be different in your version.

You might do better to use the RichTextBox control, which has various options for finding and selecting parts of the text like this.
Nov 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Adelson Anton | last post by:
Hi all, Ok, this is what I want to do: When you press, say Ctrl+K ( it doesn't matter which event), I want the , say, second word in the document to be highlighted. Anyone has any idea how...
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
0
by: Brian Scott | last post by:
I am currently trying to control the syntax highlighting of a richtextbox control whilst the user types. At the moment I have implemented a thread which calls the richTextBox.Invoke on a method...
4
by: Patrick Porter | last post by:
Arrrgh! I have tried everything (ok, not EVERYTHING) but i cant get solve the problem of getting syntax highlighting in a rich textbox. in the code below, im attempting to highlight all of the...
7
by: Leif902 | last post by:
After much searching of google, the closest I can find is highlighting search terms... however, this is not what I wanted to do. Does anyone know how to parse through a specific element (lets say...
14
by: > Adrian | last post by:
Is there a way of stopping text from highlighting in textbox? Many thanks, Adrian.
0
by: Scott | last post by:
Hi, I think I may have finally found a IDE/text editor that I like, but, it still haves one problem. Geany haves syntax highlighting, but it is not very good for Python. It only seems to have...
1
by: thetechgeek | last post by:
Hey all, I've created a pretty nice-looking drop-down menu, and I need to prevent users form highlighting the text in the menu item, because it looks kind of ugly. Here's an snippet of my menu...
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.