Press Enter to initiate Event in Visual Basics

  • Thread starter Thread starter JasonRox
  • Start date Start date
  • Tags Tags
    Basics Visual
Click For Summary

Discussion Overview

The discussion revolves around enhancing a game developed in Visual Basic by allowing the player to press "Enter" to submit answers instead of clicking a button. Participants also address an issue regarding the cursor in the textbox remaining visible during input.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant describes the current game mechanics and expresses a desire to streamline the process by using the "Enter" key instead of clicking a button.
  • Another participant asks for clarification on whether the discussion pertains to Visual Basic .NET.
  • A suggestion is made to use the textbox_KeyUp event to check for the "Enter" key and trigger the button processing.
  • A participant reports an error related to the KeyCode not being recognized and seeks clarification on the code structure.
  • Further guidance is provided on ensuring the form can catch key strokes and how to implement the KeyDown event to handle the "Enter" key.
  • Advice is given on suppressing the system sound that occurs when the "Enter" key is pressed.
  • A participant expresses gratitude and confirms that the solution worked, enhancing the game's convenience.

Areas of Agreement / Disagreement

Participants generally agree on the approach to implement the "Enter" key functionality, but there are some technical clarifications and error reports that indicate varying levels of understanding and implementation.

Contextual Notes

Some participants mention specific coding issues and errors, indicating that there may be missing assumptions or dependencies on the development environment and configurations.

JasonRox
Homework Helper
Gold Member
Messages
2,394
Reaction score
4
Ok so I'm trying to make this game I made easier to play because rightnow it's a pain.

Here's how the game playing goes now..

Click "Button"... Get Word In Textbox
Type in an Answer
Click "Button" to see if right and new word comes up


So the typing to click and typing and clicking is just a pain in the butt. Because to complete the game, you need to get 130 questions right. The game finishes fast but would be faster if the darn clicking wasn't need and I can just press "Enter" to activate the "Button".

THANKS!



The next question is that I want the little typing thing that "flashes" to STAY in the typing box.

Thanks!
 
Technology news on Phys.org
Visual Basic .NET?
 
DavidSnider said:
Visual Basic .NET?

Yes! :)

Well, it's like VB Basics Express or something.
 
DavidSnider said:
if e.KeyCode = Keys.Enter then


I get an underline for that code saying like... Keycode not in system.args or something
 
JasonRox said:
I get an underline for that code saying like... Keycode not in system.args or something

Does your code look like this?

Code:
Private Sub textBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textBox1.KeyUp
    If e.KeyCode = Keys.Enter Then
...
    End If
End Sub
 
Last edited:
The first thing you need to do is make your form capable of catching key strokes: Me.KeyPreview = True (you can put this in your form load event)

Next you need to add a sub to handle the KeyDown event. In the IDE click on your textbox then look at the properties window and click on the Events icon (it looks like a lightning bolt). You should see one named "KeyDown". Double click it and it will create the sub for you.

Next you need to add your code to the sub to handle the event. Since you want to handle the Enter key stroke it might look something like this:

Code:
If e.KeyCode = Keys.Enter Then
        'pur your code here to handle the event.
Endif

If you have sound schemes enabled on your OS then your next question may be: How do I get rid of the ding sound when I press the Enter key? It can be annoying. :)

Include this with your code to stop the ding: e.SuppressKeyPress = True
 
Last edited:
Thanks HUGE guys!

I got it working! So much MORE convenient to play now.

I will publish soon. It's a language game that helps you grow your vocabulary.
 

Similar threads

Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
7
Views
4K
  • · Replies 12 ·
Replies
12
Views
8K
  • · Replies 15 ·
Replies
15
Views
7K
Replies
1
Views
6K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K