473,221 Members | 2,003 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,221 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 3030
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.