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. - Private Sub TextBox1_KeyPress(ByVal KeyAscii As Integer)
-
If KeyAscii = 13 Then WebBrowser1.Navigate(TextBox1.Text)
-
End Sub
Here is my entire code incase this helps - Public Class Form1
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
WebBrowser1.Navigate(TextBox1.Text)
-
End Sub
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
-
WebBrowser1.Refresh()
-
End Sub
-
-
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
-
WebBrowser1.GoForward()
-
End Sub
-
-
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
-
WebBrowser1.GoBack()
-
End Sub
-
-
Private Sub TextBox1_KeyPress(ByVal KeyAscii As Integer)
-
If KeyAscii = 13 Then WebBrowser1.Navigate(TextBox1.Text)
-
End Sub
-
-
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!
9 1602
Did I post in the wrong forum or something?
question moved to .NET forum.
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. -
-
<asp:Panel ID="Panel1" DefaultButton="Button1" runat="Server>
-
<asp:Textbox ID="TextBox1" runat="Server" />
-
<asp:Button ID="Button1" Text="Click Me!" runat="Server" />
-
</asp:Panel>
Does this make sense? Let me know if this helps.
Dr B
This is a windows application yes?
Your event handler routine does not match the correct keypress event handler -
Private Sub TextBox1_KeyPress(ByVal sender As object, ByVal e As KeyPressEventArgs)
-
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!
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
You wrote just a sub, without telling the program when to use it. You can fix that like this: - Private Sub TextBox1_KeyPress(ByVal sender As object, ByVal e As KeyPressEventArgs) Handles Textbox1.KeyPress
-
If e.KeyCode = Keys.Return Then
-
WebBrowser1.Navigate(TextBox1.Text)
-
End If
-
End Sub
Now, the program knows that when you hit a key in the textbox, it should check whether Return has been hit.
Steven
You wrote just a sub, without telling the program when to use it. You can fix that like this: - Private Sub TextBox1_KeyPress(ByVal sender As object, ByVal e As KeyPressEventArgs) Handles Textbox1.KeyPress
-
If e.KeyCode = Keys.Return Then
-
WebBrowser1.Navigate(TextBox1.Text)
-
End If
-
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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) ...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
| |