This is the keypress event. It takes text that is written in a multiline text box, and places into a string for later use, the text that has been edited after the last "enter" button pressed. for example:
This is line 1 <uneditable>
This is line 2 <uneditable>
This line is newest line <editable>
so at the end of line 3 when enter is pressed it copies that line into a string for use and sets the variable "messageindex" as the length of the complete string
What I want to do is this: when a button is pressed, it checks to see if the caret is within the "editable" text (the text AFTER messageindex). If it is in the "uneditable" text area (before the messageindex) it will not allow the keypress event to go through
The problem I am having is how to stop the event from happening if the caret is in the uneditable text area
************************************************************
Friend WithEvents PlayerBox As New TextBox
Private Sub PlayerBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles PlayerBox.KeyPress
index = PlayerBox.SelectionStart()
If index <= messageindex Then
'END THE SUB AND PREVENT THE BUTTONPRESS EVENT FROM HAPPENING
End If
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
message = PlayerBox.Text.Substring(messageindex)
messageindex = PlayerBox.Text.Length()
End If
End Sub
This is line 1 <uneditable>
This is line 2 <uneditable>
This line is newest line <editable>
so at the end of line 3 when enter is pressed it copies that line into a string for use and sets the variable "messageindex" as the length of the complete string
What I want to do is this: when a button is pressed, it checks to see if the caret is within the "editable" text (the text AFTER messageindex). If it is in the "uneditable" text area (before the messageindex) it will not allow the keypress event to go through
The problem I am having is how to stop the event from happening if the caret is in the uneditable text area
************************************************************
Friend WithEvents PlayerBox As New TextBox
Private Sub PlayerBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles PlayerBox.KeyPress
index = PlayerBox.SelectionStart()
If index <= messageindex Then
'END THE SUB AND PREVENT THE BUTTONPRESS EVENT FROM HAPPENING
End If
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
message = PlayerBox.Text.Substring(messageindex)
messageindex = PlayerBox.Text.Length()
End If
End Sub