cesarfrancisco
Active member
- Joined
- Apr 3, 2007
- Messages
- 33
- Programming Experience
- Beginner
There are two Richtextboxes on the Form, part of a Calculator application.
The Display is where the numbers and operators are entered into.
The Info is where the Length of the string and the caret position is shown.
When Keys are used as the entry method then all is well.
I also use the MouseMove to achieve the same result, in case the mouse is placed into the Display.
End If
End Sub
----------------------------------------------------------------------------------------------
The problem arise when the Mouse is used to click on the the buttons representing the numbers or the operators.
Although the Display.Focus will place the caret into the Display Richtextbox. The caret will not move from its starting position.
The Display is where the numbers and operators are entered into.
The Info is where the Length of the string and the caret position is shown.
When Keys are used as the entry method then all is well.
Private Sub Display_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Display.KeyUp
Dim stringpos As Integer
If CType(e.KeyCode, Integer) > 95 And CType(e.KeyCode, Integer) < 106 Or CType(e.KeyCode, Integer) = 37 Or CType(e.KeyCode, Integer) = 39 Then
stringpos = Display.SelectionStart
Info.Text = "Length " + mystring & " Position " & (stringpos).ToString
End If
End Sub
I also use the MouseMove to achieve the same result, in case the mouse is placed into the Display.
Private Sub Display_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Display.MouseMove
mystring = (Display.Text.Length).ToString
If Display.SelectionLength > 0 Then
Display.Copy()
A = Display.SelectedText
End If
If e.Button = MouseButtons Then
Dim stringpos As Integer = Display.GetCharIndexFromPosition(New Point(e.X, e.Y))
If stringpos <> -1 Then
mystring = (Display.Text.Length).ToString
Info.Text = "Length " + mystring & " Position " & (stringpos).ToString
If Display.SelectionLength <> 0 Then
Info.Text = "Length " + mystring & " Position " & (stringpos).ToString & " Selected text [" & A & "]: " & A
End If
End If
End If
End Sub
----------------------------------------------------------------------------------------------
The problem arise when the Mouse is used to click on the the buttons representing the numbers or the operators.
Although the Display.Focus will place the caret into the Display Richtextbox. The caret will not move from its starting position.
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b0.Click, b1.Click, b2.Click, b3.Click, b4.Click, b5.Click, b6.Click, b7.Click, b8.Click, b9.Click, bDot.Click, bAdd.Click, bDivide.Click, bMultiply.Click, bSubtract.Click
Display.Text = Display.Text + CType(sender, Button).Text
mystring = (Display.Text.Length).ToString
Dim stringpos As Integer
Info.Text = "Length " + mystring & " Position " & (stringpos).ToString
Display.Select() ' or Display.Focus()
End Sub