473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problems with the Return key

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 1602
Did I post in the wrong forum or something?
Jul 29 '08 #2
debasisdas
8,127 Expert 4TB
question moved to .NET forum.
Jul 29 '08 #3
DrBunchman
979 Expert 512MB
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 Expert 4TB
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
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 Expert 512MB
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 Expert 512MB
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
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.KeyPressEventArgs'.

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

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

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
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...
2
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...
13
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...
9
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...
10
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) ...
1
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...
2
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...
6
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...
10
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...
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.