Check is Keys are pressed in KeyDown Event

ryoka012

Active member
Joined
Oct 13, 2011
Messages
32
Programming Experience
Beginner
Hi Guys,

How to know if i enter a text after i press Enter

VB.NET:
    Private Sub RichTextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles RichTextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
              'check here if i enter a text 
        End If
    End Sub

Thanks guys,
 

ryoka012

Active member
Joined
Oct 13, 2011
Messages
32
Programming Experience
Beginner
Hi jmcilhinney,


thanks for the reply.

sorry for the confusion, but i just want to check if the user press other key after the user press the enter key.

Scenario

On the first line the user does not press the enter key until on the third line.
And check if the user type a letter after the user press the enter key.
Or the user will continue to press the enter key without typing any letter.


thanks and best regards.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
That sounds like an awful lot of overhead, why do you need a richtextbox and keeping tabs on carrot lines?
 

ryoka012

Active member
Joined
Oct 13, 2011
Messages
32
Programming Experience
Beginner
Hi juggalobrotha,

Yup, the reason for that is to count all the lines.
With the exception of the lines which are empty.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,543
Location
Norway
Programming Experience
10+
to count all the lines.
With the exception of the lines which are empty.
Dim nonEmptyLineCount = Me.RichTextBox1.Lines.Count(Function(line) line.Length > 0)
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,481
Location
Sydney, Australia
Programming Experience
10+
Hi juggalobrotha,

Yup, the reason for that is to count all the lines.
With the exception of the lines which are empty.
In future, please lead with what you're trying to achieve rather than how you're trying to achieve it. There's no point our helping you do something that's a bad idea in the first place. If we know why you're trying to do what you're trying to do, we can let you know whether it's actually worth trying to do it or whether there's something else you should be trying instead.
 

ryoka012

Active member
Joined
Oct 13, 2011
Messages
32
Programming Experience
Beginner
Hi jmcilhinney,

Sorry for the confusion.
And thanks you for reminding me.

Will do it in the future.


Hi JohnH,


Thank you for the code.It Works.
 
Top Bottom