Link to home
Start Free TrialLog in
Avatar of tbeck1983
tbeck1983Flag for United States of America

asked on

How to send shif+enter when enter key is pressed

I have a richtextbox control on a form.  If a user presses enter on the richtextbox I want to send a shift+enter instead.  Problem with my code is it goes into an infinate loop.
Private Sub txtNotes_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNotes.KeyDown
        If e.KeyCode = Keys.Enter Then
            e.Handled = True
            SendKeys.Send("+ENTER")
        End If
    End Sub

Open in new window

Avatar of tbeck1983
tbeck1983
Flag of United States of America image

ASKER

I forgot to mention the reason I want to shif+enter is because my richtextbox is a bullet list and after each bullet I want a blank line.
SOLUTION
Avatar of VBRocks
VBRocks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank's for the quick post.  However, it still loops on the sendkeys event.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the reply.  It still loops though.
Really?  I did it on my pc, it only executed once.  Sorry it's not working for you.

Avatar of Mike Tomlinson
How about this instead?...

Just check to see if Shift is pressed down with Enter...and if not, send it:
    Private Sub txtNotes_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNotes.KeyDown
        If Not e.Shift AndAlso e.KeyCode = Keys.Enter Then
            e.Handled = True
            SendKeys.Send("+{ENTER}")
        End If
    End Sub

Open in new window