Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:15:19+00:00 2026-06-17T15:15:19+00:00

I wanted to check if a key was pressed in a form, then perform

  • 0

I wanted to check if a key was pressed in a form, then perform a subroutine with that key. The code below works only if there are no other controls in the form. What should I do?

Private Sub MainForm_KeyPress1(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
    MsgBox(e.KeyChar)
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:15:20+00:00Added an answer on June 17, 2026 at 3:15 pm

    You can set the KeyPreview property of your form to True. This way, you’ll catch all the KeyPress events on your form (which will be afterwards handled by the control the keypress happened on, if you didn’t set the Handled property of the KeyPressEventArgs to True).

    When this property is set to true, the form will receive all KeyPress,
    KeyDown, and KeyUp events. After the form’s event handlers have
    completed processing the keystroke, the keystroke is then assigned to
    the control with focus. For example, if the KeyPreview property is set
    to true and the currently selected control is a TextBox, after the
    keystroke is handled by the event handlers of the form the TextBox
    control will receive the key that was pressed. To handle keyboard
    events only at the form level and not allow controls to receive
    keyboard events, set the KeyPressEventArgs.Handled property in your
    form’s KeyPress event handler to true.

    Source: MSDN

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I have three different tables (check below). I wanted to make that I
Just wanted to check if there is any configuration or parameter to get statistics
Wanted to know if someone had a suggestion on code or maybe there's a
Is there any .NET type that would represent a set of key-value pairs where
I have a php page that submits form to itself. I wanted to add
The below code will block all the keyboard shortcuts. Since i wanted to implement
I wanted to check if there was a way of encoding an integer into
I wanted to know if data is present then there must be mysql update
I have this html code : <div id=jiraTicketAccordion> <div> <h3><a href=#>key</a></h3> <div> <form> <div
I wanted to check whether the variable is defined or not. For example, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.