Sign in to follow this  

text in c#

This topic is 4096 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Quote:
Original post by sic0198
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.


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 this post


Link to post
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);
}
}
}

Share this post


Link to post
Share on other sites

This topic is 4096 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this