# text in c#

## Recommended Posts

Though this not a game development questino I think for me to lern to build things in c# is a good start to learm game development. I need some help. I am trying to build a web browser, I got it working except I need help with the entering of the URL. I wanna be able to type the url in and it goes there, right now I have a combo box with urls to switch from and when you pick one it goes there when you press the go button. Could anyone give me a hand or point me in the right direction to find it on my own?

##### Share on other sites
You want to look at the events that are available to the owner of the combo box, spcifically something along the lines of TextChanged.

Skizz

##### Share on other sites
Quote:
 Original post by sic0198I wanna be able to type the url in and it goes there, right now I have a combo box with urls to switch from and when you pick one it goes there when you press the go button.

Your post is somewhat confusing, but from that sentance I assume you mean that you don't want people to have to pick the 'go' button.

There are several events you can listen for that might be useful. SelectionChangeCommitted, DropDownClosed, KeyPress, TextChanged, Validating, and others event handlers may fit your needs. When you detect a suitable change (enter key pressed, or selection changed, or picking something from the dropdown, or whatever else), then take the action at that point.

Some events are triggered every time a key is pressed, others only after editing. Use whichever fits your needs.

##### Share on other sites
Here is an example the triggers off a new URL being typed followed by "Enter". It will load the web page if the URL is changed or a new one is added. Obviously, you would have to handle more then just Enter, but it will get you going.

namespace WindowsApplication1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void comboBoxURL_SelectedIndexChanged(object sender, EventArgs e)        {            string selected = comboBoxURL.Items[comboBoxURL.SelectedIndex].ToString();            if ( selected!= null && selected != "")            {                if (selected.StartsWith("http:://") == false)                    selected = String.Format("{0}{1}", "http://", selected);                webBrowser1.Url = new Uri(selected);            }        }        private void comboBoxURL_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.Enter)            {                if (comboBoxURL.SelectedIndex == -1 )                {                    // NEW URL?                    if (comboBoxURL.Items.Contains(comboBoxURL.Text))                    {                        comboBoxURL.SelectedIndex = comboBoxURL.Items.IndexOf(comboBoxURL.Text);                    }                    else // its new                    {                        comboBoxURL.Items.Add(comboBoxURL.Text);                        comboBoxURL.SelectedIndex = comboBoxURL.Items.Count - 1;                    }                }                e.Handled = true;            }            base.OnKeyDown(e);        }    }}

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627644
• Total Posts
2978372

• 10
• 12
• 22
• 13
• 33