Ctrl+N To Open New Browser Window
The File menu in a web browser project has a sub-menu New. New also has a sub-menu Window named mnuNewWindow. Clicking the Window menu, as usual, opens a new instance of the browser. Ctrl+N has been assigned the shortcut key for Window at design time.
Now what I find is if I press Ctrl+N on the keyboard, not only a new browser window opens but at the same time Windows Explorer's C:\ drive opens up as well (maybe because that is where WinXP is installed).
If I change the shortcut key of Window to, say, Ctrl+Q & press Ctrl+Q on the keyboard, then only a new browser window opens up. I also tried other shortcut combinations & all of them open only a new browser window (& not C:\ along with the new browser window). The problem is only with Ctrl+N. This is how I tried it:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (Shift = 2 And KeyCode = 78) Then
Call mnuNewWindow_Click
End If
End Sub
Private Sub mnuNewWindow_Click()
Dim frmNewWindow As frmWebBrowser
Set frmNewWindow = New frmWebBrowser
frmNewWindow.Show
frmNewWindow.wWeb.Navigate2 "http://www.SomeURL.com"
End Sub
What's causing this problem? How do I ensure that pressing Ctrl+N only opens a new browser window?
Note that I have set the KeyPreview property of the Form which houses the WebBrowser control to True.
Of course, I can assign any other shortcut to Window but since Ctrl+N has been the universally accepted key combination to open a new instance of an app, I did like to adhere to Ctrl+N to open a new browser window.
Re: Ctrl+N To Open New Browser Window
Question, and I don't know if this relates to your problem: Why not just assign Ctrl+N as the shortcut key using the menu editor? This will eliminate the need for the code in the KeyDown event, and should give more clarity on the matter.
My suspicions are that, when you hit CTRL+N, the main form sees the event, opens the frmnewWindow, and then as the webbrowser control is selected, it fires CTRL+N again... (Like a delay on the keyboard almost...)
If you change it to use CTRL+O, does it show an Open dialog?
Re: Ctrl+N To Open New Browser Window
Quote:
Why not just assign Ctrl+N as the shortcut key using the menu editor?
That's what I first did but since it didn't work, I added the code in the Form's KeyDown event.
Any other suggestions?
Re: Ctrl+N To Open New Browser Window
Temporarily change the shortcut to CTRL+O and check if an open dialog pops up. If this happens, we at least know what the problem is.
Solving it will be a bit harder, though. :)
Re: Ctrl+N To Open New Browser Window
No Ctrl+O does not invoke the open dialog. In fact, nothing happens though I have set it as a shortcut key in the Menu Editor (which should open a new Form similar to the dialog that opens up when you press Ctrl+O in IE.