473,322 Members | 1,846 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,322 software developers and data experts.

Select and modify data within a RichTextBox by mouse click

I am having a problem with RichTextBox Control and hope you can help

I am working on a VB.Net project that has a RTB control, the user opens a form template. What I want to do is for a user to be able to click or right click on text within the form such as Priority: [[|Low|Medium|High]]. If the user clicked on Low the brackets and bars would go away and leave Priority: Low. And the same for Medium and High

Is there any way to do that

Nov 20 '05 #1
1 3035
I am pretty sure someone else can do this better, but here is a solution.
If nothing else, you can use what I did as a rough template and improve on
it.

----------------------------
Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDown
If e.Button = MouseButtons.Right Then
Dim CharIndex As Int32
Dim StartPos As Int32
Dim EndPos As Int32
Dim SelText As String
Dim Options() As String
Dim SelItem As String
Dim RunningLength As Int32
' get the position of the character they clicked at
CharIndex = RichTextBox1.GetCharIndexFromPosition(New Point(e.X,
e.Y))
' find the start and end of the option list
EndPos = RichTextBox1.Text.IndexOf("]", CharIndex) + 1
StartPos = RichTextBox1.Text.LastIndexOf("[", CharIndex)
' leave if they did not click inside of an option
If EndPos = -1 Or StartPos = -1 Or StartPos > EndPos Then
Exit Sub ' not inside of a [] section
End If
CharIndex -= StartPos
' select the total text area of the option list
RichTextBox1.Select(StartPos, EndPos - StartPos)

' get the total text area of the option list
SelText = RichTextBox1.SelectedText
Options = SelText.Split("|")

' find the item the user click on
For Each SelItem In Options
RunningLength += SelItem.Length + 1
If CharIndex < RunningLength Then
' found the item they selected, display that item
RichTextBox1.SelectedText = SelItem.Replace("[",
"").Replace("]", "")
Exit For
End If
Next

End If
End Sub
-------------------------------------

PS. still has some issues if there is more then one option list
"HJ Majoue" <an*******@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
I am having a problem with RichTextBox Control and hope you can help.

I am working on a VB.Net project that has a RTB control, the user opens a form template. What I want to do is for a user to be able to click or right
click on text within the form such as Priority: [[|Low|Medium|High]]. If
the user clicked on Low the brackets and bars would go away and leave
Priority: Low. And the same for Medium and High.
Is there any way to do that.

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: MD | last post by:
I have a ContextMenu that is assigned to 3 RichTextBox's (i.e., if you right-click on any of the 3 RichTextBox's, you get the same ContextMenu). My ContextMenu has 2 items, each of which have their...
0
by: Sakharam Phapale | last post by:
Hi All, How to insert the image into the richtextbox control and catch the mouse click event of that image. Thanks in Advance, Sakharam Phapale
3
by: Rachel Suddeth | last post by:
I want to react to scrolls in a RichTextBox (I want to let the user know when he has changed to a new printable page.) I have handled the VScroll() event, but that only responds to scrollbar...
3
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
0
by: Lou | last post by:
Dear all, I have two questions and need to get some hints from u. :0) 1. Editor with the syntax functionality. In my ongoing editor, when the user types the word, e.g. "ABC", the word "ABC"...
5
by: visu | last post by:
Hi this is a question asked in this group two years back.. No answer for this question till date. now i am in the same situation of the questioner.. to find a solution for this problem. Can any...
4
by: Aussie Rules | last post by:
Hi, I want to be able to show a txt file(stored on disk) to the end user in some sort of txt editor control, and allow the user to highlight/select words within the text. Once they have...
0
by: Linda Liu[MSFT] | last post by:
Hi CES, Thank you for posting here! I notice that you post a same issue in the microsoft.public.dotnet.framework.windowsforms.controls newsgroup and I have replied to that thread. For your...
1
by: Andrus | last post by:
I need to save font selected by user by Ctrl+MouseWheel in Winforms RichTextBox. I tried override below but this does not remember font: in this method Font.Size property seems to be always...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.