Click here to Skip to main content
16,004,977 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,

Well, Friends i,am working on a project called WebBrowser and now i wants to add some shortcut keys to my project like "Ctrl+Enter" When the user type some websites name on address textbox url its should directly redirect to entire web address name like we normally do type "Yahoo" then ctrl+enter its redirect to http://www.yahoo.com so i want to implement same shortcut to my project as well.
I'am Using Visual Studio 2010.
Friends Plz help..

Thanks in Advance:)
Posted

Use the keydown event of textbox // i suppose you are using a textbox control for entering URL

C#
private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Enter) // to check whether cntrl key + enter key are pressed

                    textBox1.Text = "http://www." + textBox1.Text + ".com";

// Now use this textbox text to redirect

            }
        }




----Prathap.
 
Share this answer
 
v2
Comments
Nikhil@123 14-Nov-12 2:13am    
Hi Pratap,

i have tried followed code in my Project, but its not working at all not even showing me an error. Here i am mentioning my code. Plz help me to re-modify.
Thanks


private void adrBarTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
getCurrentBrowser().Navigate(adrBarTextBox.Text);
}
else
{

if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Enter)
{
adrBarTextBox.Text = "http://www." + adrBarTextBox.Text + ".com";
}

}
Hi Nikhil,

This should work fine.Everything seems ok.But you didn't navigate the text after concatenation.

C#
private void adrBarTextBox_KeyDown(object sender, KeyEventArgs e)
 { 
if (e.KeyCode == Keys.Enter) 
 {
 getCurrentBrowser().Navigate(adrBarTextBox.Text);
 } 
else 
 { 
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Enter)
  { 
adrBarTextBox.Text = "http://www." + adrBarTextBox.Text + ".com"; 
getCurrentBrowser().Navigate(adrBarTextBox.Text);
   }
 }
}


If this is not working.First just try the code and check whether the textbox text is concatenated after pressing Cntrl+Enter key

C#
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Enter) // to check whether cntrl key + enter key are pressed

      textBox1.Text = "http://www." + textBox1.Text + ".com";
 
Share this answer
 
Comments
Nikhil@123 15-Nov-12 23:26pm    
Hi nkkppp,

Yes now its working fine after navigating the textbox, thanks a lot Bro... :)
Prathap Gangireddy 15-Nov-12 23:40pm    
Hi Nikhil,

Mark it as solved so that it will be helpful to others.

---Prathap.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900