Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 How to detect character position (index) of click in RichTextBox

$
0
0
I'm making an app that allows the user to easily write words/phrases/sentences in phonemes. I made a series of buttons and put a picture of the phoneme on each one and copied the SIL Manuscript character for that symbol into the Tag property of the buttons. When a button is pressed, that symbol is appended to the end of the text string in the RichTextBox at the top.Attachment 95209
All goes well if the user types everything correctly first time - not likely! The user can click in the RichTextBox but then clicking a button still appends the symbol at the end. The only way is to use [BS] to delete the symbols to the correct point and then continue.
What I would like is some way of detecting the point in the RichTextBox that the user clicks and then insert subsequent characters at that point.
For interest, the code I have at present is below. Can anyone point me in the right direction please.
vb.net Code:
  1. Public Class frmPhoneme
  2.  
  3.     Private Sub PhonemePress(sender As System.Object, e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click,
  4.         Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, Button11.Click,
  5.         Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click, Button17.Click, Button18.Click, Button19.Click,
  6.         Button20.Click, Button21.Click, Button22.Click, Button23.Click, Button24.Click, Button25.Click, Button26.Click, Button27.Click,
  7.         Button28.Click, Button29.Click, Button30.Click, Button31.Click, Button32.Click, Button33.Click, Button34.Click, Button35.Click,
  8.         Button36.Click, Button37.Click, Button38.Click, Button39.Click, Button40.Click, Button41.Click, Button42.Click, Button43.Click,
  9.         Button44.Click, Button48.Click, Button50.Click, Button51.Click
  10.         Dim Btn As Button = DirectCast(sender, Button)
  11.         RichTextBox1.Text += Btn.Tag.ToString
  12.     End Sub
  13.  
  14.     Private Sub Button46_Click(sender As System.Object, e As System.EventArgs) Handles Button46.Click
  15.         RichTextBox1.Text = ""
  16.     End Sub
  17.  
  18.     Private Sub Button49_Click(sender As System.Object, e As System.EventArgs) Handles Button49.Click
  19.         Me.Close()
  20.     End Sub
  21.  
  22.     Private Sub Button47_Click(sender As System.Object, e As System.EventArgs) Handles Button47.Click
  23.         Clipboard.SetDataObject(RichTextBox1.Text, True)
  24.     End Sub
  25.  
  26.     Private Sub RichTextBox1_Click(sender As Object, e As System.EventArgs) Handles RichTextBox1.Click
  27.  
  28.     End Sub
  29.  
  30.     Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged
  31.  
  32.     End Sub
  33. End Class
Attached Images
 

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>