Determine whether user pressed Enter key : Key Event « Event « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Event » Key Event 
11.6.3.Determine whether user pressed Enter key
Determine whether user pressed Enter key
Imports System.Windows.Forms


public class KeyCodeEnter
   public Shared Sub Main
        Application.Run(New FrmFileTest)
   End Sub
End class

Public Class FrmFileTest
   Inherits Form

   ' label that gives directions to user
   Friend WithEvents lblDirections As Label

   ' text boxes for inputting and outputting data
   Friend WithEvents txtOutput As TextBox
   Friend WithEvents txtInput As TextBox

#Region " Windows Form Designer generated code "

   Public Sub New()
      MyBase.New()

      'This call is required by the Windows Form Designer.
      InitializeComponent()

      'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is NothingThen
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.Container

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
      Me.lblDirections = New System.Windows.Forms.Label()
      Me.txtOutput = New System.Windows.Forms.TextBox()
      Me.txtInput = New System.Windows.Forms.TextBox()
      Me.SuspendLayout()
      '
      'lblDirections
      '
      Me.lblDirections.Font = New System.Drawing.Font("Microsoft Sans Serif"10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.lblDirections.Location = New System.Drawing.Point(2020)
      Me.lblDirections.Name = "lblDirections"
      Me.lblDirections.Size = New System.Drawing.Size(41019)
      Me.lblDirections.TabIndex = 2
      Me.lblDirections.Text = "Press Enter key:"
      Me.lblDirections.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
      '
      'txtOutput
      '
      Me.txtOutput.AutoSize = False
      Me.txtOutput.BackColor = System.Drawing.SystemColors.Control
      Me.txtOutput.Font = New System.Drawing.Font("Microsoft Sans Serif"10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.txtOutput.Location = New System.Drawing.Point(20109)
      Me.txtOutput.Multiline = True
      Me.txtOutput.Name = "txtOutput"
      Me.txtOutput.ReadOnly = True
      Me.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
      Me.txtOutput.Size = New System.Drawing.Size(410345)
      Me.txtOutput.TabIndex = 1
      Me.txtOutput.Text = ""
      '
      'txtInput
      '
      Me.txtInput.Font = New System.Drawing.Font("Microsoft Sans Serif"10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.txtInput.Location = New System.Drawing.Point(2059)
      Me.txtInput.Name = "txtInput"
      Me.txtInput.Size = New System.Drawing.Size(41026)
      Me.txtInput.TabIndex = 0
      Me.txtInput.Text = ""
      '
      'FrmFileTest
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(615)
      Me.ClientSize = New System.Drawing.Size(460470)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtOutput, Me.lblDirections, Me.txtInput})
      Me.Name = "FrmFileTest"
      Me.Text = "File Test"
      Me.ResumeLayout(False)

   End Sub

#End Region

   ' invoked when user presses key
   Protected Sub txtInput_KeyDown(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.KeyEventArgsHandles _
      txtInput.KeyDown

      
      If e.KeyCode = Keys.Enter Then
          Console.WriteLine("Enter")

      End If 

   End Sub 

End Class
11.6.Key Event
11.6.1.Check Key Code: F5Check Key Code: F5
11.6.2.Displaying information about a user-pressed keyDisplaying information about a user-pressed key
11.6.3.Determine whether user pressed Enter keyDetermine whether user pressed Enter key
11.6.4.Ignore key codeIgnore key code
11.6.5.Key event summaryKey event summary
11.6.6.Control KeyControl Key
11.6.7.Shift KeyShift Key
11.6.8.Check Key Code rangeCheck Key Code range
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.