Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to suppress textbox.keypress events

Status
Not open for further replies.

BrianJH

Programmer
May 26, 2003
26
US
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 &quot;messageindex&quot; 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 &quot;editable&quot; text (the text AFTER messageindex). If it is in the &quot;uneditable&quot; 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
 
Thank you JohnYingLing for the reply. It works perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top