How to add the enter button command.

How do i make it so when they press the enter button...

Page 1 of 1

3 Replies - 2159 Views - Last Post: 01 November 2009 - 09:53 AM Rate Topic: -----

#1 C++ Programmer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 20
  • View blog
  • Posts: 548
  • Joined: 12-June 08

How to add the enter button command.

Posted 31 October 2009 - 09:49 AM

How do I make it so that when they press the enter button it brings them to where they typed in the URL bar. The program works, but you have to click the Go button to goto the website, how do i make it so that when they press the enter button it does the same thing?

Here is my code. Just tell me the void for the enter button.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Web_Browser
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void gobutton_Click(object sender, EventArgs e)
		{
			webBrowser1.Navigate(textBox1.Text);
		}

		private void backbutton_Click(object sender, EventArgs e)
		{
			webBrowser1.GoBack();
		}

		private void fowardbutton_Click(object sender, EventArgs e)
		{
			webBrowser1.GoForward();
		}

		private void refreshbutton_Click(object sender, EventArgs e)
		{
			webBrowser1.Refresh();
		}

		private void stopbutton_Click(object sender, EventArgs e)
		{
			webBrowser1.Stop();
		}

		private void homebutton_Click(object sender, EventArgs e)
		{
			webBrowser1.GoHome();
		}
	}
}


thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How to add the enter button command.

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: How to add the enter button command.

Posted 31 October 2009 - 09:54 AM

Add a KeyPress event to your textBox1.
Was This Post Helpful? 0
  • +
  • -

#3 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: How to add the enter button command.

Posted 31 October 2009 - 10:03 AM

Another alternative would be to go to the properties for your form and set the AcceptButton property to gobutton. What that will do is if the user presses the Enter key it will trigger the event handler for gobutton.
Was This Post Helpful? 0
  • +
  • -

#4 C++ Programmer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 20
  • View blog
  • Posts: 548
  • Joined: 12-June 08

Re: How to add the enter button command.

Posted 01 November 2009 - 09:53 AM

Thank You :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1