Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 AdvanceSmile | :)
Posted 11-Nov-12 20:31pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use the keydown event of textbox // i suppose you are using a textbox control for entering URL
 
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.
  Permalink  
v2
Comments
Nikhil@123 at 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";
}
 
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Nikhil,
 
This should work fine.Everything seems ok.But you didn't navigate the text after concatenation.
 
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
 
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";
  Permalink  
Comments
Nikhil@123 at 15-Nov-12 23:26pm
   
Hi nkkppp,
 
Yes now its working fine after navigating the textbox, thanks a lot Bro... :)
nkkppp at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100