473,811 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with the Return key

4 New Member
Hi! I'm very new to Visual Basic Express 2008 and I am trying to get a basic knowledge of the program so I took the tutorial that shows you how to make a basic webbrowser. Well I took it a little farther and added buttons like go forward/back refresh ect..

The problem I am having is this: When im typing in a web address and press the return key I want that to be the same as pressing the go button... Here is the code I have and it doesn't say anything is wrong it just doesn't work.

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(ByVal KeyAscii As Integer)
  2.         If KeyAscii = 13 Then WebBrowser1.Navigate(TextBox1.Text)
  3.     End Sub
Here is my entire code incase this helps

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         WebBrowser1.Navigate(TextBox1.Text)
  4.     End Sub
  5.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  6.         WebBrowser1.Refresh()
  7.     End Sub
  8.  
  9.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  10.         WebBrowser1.GoForward()
  11.     End Sub
  12.  
  13.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  14.         WebBrowser1.GoBack()
  15.     End Sub
  16.  
  17.     Private Sub TextBox1_KeyPress(ByVal KeyAscii As Integer)
  18.         If KeyAscii = 13 Then WebBrowser1.Navigate(TextBox1.Text)
  19.     End Sub
  20.  
  21. End Class
I've read stuff about "focus" but I'm not sure how to use that or if I even need to.

Please I have been having a LOT of trouble with this so any help will be awesome!
Jul 27 '08 #1
9 1621
BowserYo
4 New Member
Did I post in the wrong forum or something?
Jul 29 '08 #2
debasisdas
8,127 Recognized Expert Expert
question moved to .NET forum.
Jul 29 '08 #3
DrBunchman
979 Recognized Expert Contributor
Hi BowserYo,

Have you defined this subroutine as an event anywhere? How does your code know that it is supposed to fire this sub when you press the enter key?

An easier way to achieve what you want would probably be to put TextBox1 and Button1 inside a Panel and set the DefaultButton property of the panel to the ID of Button1. Doing so means that while the panel has focus (i.e. while the user is clicking or typing in a control inside that panel) then pressing return will always act like you have clicked on Button1. Your Button1_Click event will then fire and redirect your user.

Here's an example of what I'm talking about.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <asp:Panel ID="Panel1" DefaultButton="Button1" runat="Server>
  3.      <asp:Textbox ID="TextBox1" runat="Server" />
  4.      <asp:Button ID="Button1" Text="Click Me!" runat="Server" />
  5. </asp:Panel>
Does this make sense? Let me know if this helps.

Dr B
Jul 29 '08 #4
Plater
7,872 Recognized Expert Expert
This is a windows application yes?
Your event handler routine does not match the correct keypress event handler
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(ByVal sender As object, ByVal e As KeyPressEventArgs)
  2.  
Jul 29 '08 #5
BowserYo
4 New Member
Okay, They are all in a panel now... But im not 100 percent sure how I set the default button, I tried adding your code and it did not work. I also looked in the Properties of the panel but could not find a default button property. And yes this is a windows form app. But you understand what I am trying to do at least.

Plater, I am very new to this program so what you said just went over my head... Sorry guys I'm just trying to learn!
Jul 30 '08 #6
DrBunchman
979 Recognized Expert Contributor
BowserYo,

Ignore me, I mistakenly read that you were using Visual Web Developer Express - the advice I gave you would only be relevant for a webpage. Apologies for any confusion!

I'm sure Plater will be able to help you out.

Dr B
Jul 30 '08 #7
MrMancunian
569 Recognized Expert Contributor
You wrote just a sub, without telling the program when to use it. You can fix that like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(ByVal sender As object, ByVal e As KeyPressEventArgs) Handles Textbox1.KeyPress
  2.   If e.KeyCode = Keys.Return Then 
  3.      WebBrowser1.Navigate(TextBox1.Text)
  4.   End If
  5. End Sub
Now, the program knows that when you hit a key in the textbox, it should check whether Return has been hit.

Steven
Jul 30 '08 #8
BowserYo
4 New Member
You wrote just a sub, without telling the program when to use it. You can fix that like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(ByVal sender As object, ByVal e As KeyPressEventArgs) Handles Textbox1.KeyPress
  2.   If e.KeyCode = Keys.Return Then 
  3.      WebBrowser1.Navigate(TextBox1.Text)
  4.   End If
  5. End Sub
Now, the program knows that when you hit a key in the textbox, it should check whether Return has been hit.

Steven
Okay, its having some problems with "e.KeyCode"

Error 1 'KeyCode' is not a member of 'System.Windows .Forms.KeyPress EventArgs'.

Thanks all for taking the time to try and help me.
Jul 30 '08 #9
Plater
7,872 Recognized Expert Expert
Okay, its having some problems with "e.KeyCode"

Error 1 'KeyCode' is not a member of 'System.Windows .Forms.KeyPress EventArgs'.

Thanks all for taking the time to try and help me.
It's KeyChar for that object.
You should try looking at these objects yourself. Use the intellisense on objects, it can very usefull.
Jul 30 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2080
by: peter | last post by:
Hello all, Recently I've started to refactor my code ...(I'm using python 2.3.4) I tried to add extra functionality to old functions non-intrusively. When I used a construct, which involves renaming functions etc... I came across some recursive problems. (a basic construct can be found under the section BASIC CODE) These problems do not occur when renaming objects. (see section EXTRA CODE)
2
2070
by: -Steve- | last post by:
Okay I have a bunch of code below. Hope it comes across readable. The problem I'm having is that in the lines under main(): cout << a << endl; Is going into the code for IntArray(const IntArray&);. Without that function these first 5 tests work fine. Of course I need that come test6(). Also something must be wrong with the deconstructor. If I comment it out my
13
40778
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person filling out the form is switching from page to page...without the overhead of extra hits on the server,...
9
1404
by: please-answer-here | last post by:
What is wrong with this code? when i place "return false" before the xfab assignment the form as intended doesn't submit. But when placed as here or in the last if/else construct the page gets submitted regardless of any errors response.write("<form method=""POST"" action=""scandia.asp"" onSubmit=""return pre_submit_gem()"" name=""vaerksted"">") function pre_submit_gem(felt) {
10
2418
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
1
1765
by: Mario Lacunza | last post by:
--------- Mensaje reenviado -------- De: Mario Lacunza <mario.lacunza@gmail.com> Para: Lista Python Ing <python-list@python.org> Asunto: Problems with PyGridTableBase Fecha: Sat, 09 Sep 2006 00:03:20 -0500 Hello, I attach two files:frmClientes and frmClientesNE.
2
3279
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
6
1895
by: JNeko | last post by:
Hello all, awesome site! I guess I am technically not a beginner in JAVA, but from my code you would not realize it! I don’t expect anyone to help me with this, but I figure I might as well as try and ask. Any help is really appreciated; this should be a piece of cake…driving me crazy. I am writing a simple program (from a book for fun) that creates a deck of cards, shuffles them, gives the user a card, and asks if the next card will be...
10
1888
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle using the * character. The program was just for practice but I am having problems. My main problem is, in my program I use 4 functions to change or access two variables in my code. The variables are
4
6601
by: Patrick | last post by:
Hello, I'm currently trying the OpenSSL Library, but I got some problems. I want to create a server and client application that communicate through the OpenSSL API, but this code doesn't work. I tried to understand the error messages but for me they aren't useful. And now I'm here and hope that somebody has experience and can tell me the error. This is the Code for the server: #define _CRT_SECURE_NO_DEPRECATE
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10408
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9211
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5564
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4352
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3876
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3027
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.