Enable Tab Key in my Web Browser Control - vb.net

I have a web browser control in a custom task pane control (User Control) and I open it as a sidebar as soon as my Outlook opens (I have created it as an Outlook Addin using Visual Studio 2013). The web browser control has a login form inside it and I would like to place focus on an input control in my web browser control as soon as Outlook opens. I have tried several tricks like placing focus on the custom user control and then placing focus on the input control after the form has loaded but it doesn't place focus on it. Also I have been trying to allow the use of Tab and Delete keys to work inside the web browser control so that I can tab to other controls and play with it like we would do it on a normal browser window. Kindly let me know how I can achieve this as I am out of ideas.
Cheers.

Try to use the Excel WebBrowser Control instead of the System.Windows.Forms WebBrowser; it handles special key forwarding as TAB, DEL, CTRL+V, etc.
For that change the WebBrowser contructor from
new System.Windows.Forms.WebBrowser();
to
new Microsoft.Office.Tools.Excel.Controls.WebBrowser();
You would need to add references to your project:
Project/Add Referernce/Extensions select
Microsoft.Tools.Outlook & Microsoft.Tools.Outlook.v4.0.Utilities
Doc: https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.controls.webbrowser.aspx

You can only do that if you install a Windows hook (SetWindowsHookExW(WH_GETMESSAGE, YourHookProc, 0, GetCurrentThreadId()) and in the hook proc detect that messages are supposed to go to your browser, and redirect them accordingly.

It works partially this way but not 100%. First I had to set the TabStop property to True for my webbrowser control and then just set the focus once the document was loaded and that was it. The tab, delete, backspace keys all ran properly.
Private Sub CustomTaskPane_Load(sender As Object, e As EventArgs) Handles Me.Load
TestWebBrowser.Size = New Drawing.Size(Me.Width, Me.Height)
Me.Focus()
TestWebBrowser.Navigate(url)
WaitForPageLoad()
TestWebBrowser.TabIndex = 0
TestWebBrowser.TabStop = True
End Sub
Private Sub TestWebBrowser_DocumentCompleted(sender As Object, e As Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles TestWebBrowser.DocumentCompleted
' Now set the focus on the Web Browser Control
TestWebBrowser.Focus()
End Sub

Related

How to make an invisible internet explorer?

I have been playing around with VB today and was wondering on the concept of being able to load a webpage in this case radio 1 online player and but having no open browsers visible to the user even though there will be one hidden one in this case this one. Currently I have it set up to simply navigate to the site but was wondering if it was possible to do what was stated above.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim QueryAddress As New StringBuilder()
QueryAddress.Append("http://www.bbc.co.uk/radio/player/bbc_radio_one")
Process.Start(QueryAddress.ToString())
Visible = False
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Unable to station")
End Try
End Sub
If you want to play a radio station you might be better using media player and connecting to the station's radio stream.
Drop windows media player onto your form.
Set its Visible property to False.
add a button with this code inside the button's click event
AxWindowsMediaPlayer1.URL = "http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_med/llnw/bbc_radio_one.m3u8"
And of course your try..catch code as well.
Tada!
I got the url from this website by clicking on the link in the second colum and then right clicking on the data rate that I wanted and copying the linked addres. I then pasted it into the vb.net code that you see

using ppDisp to take control of popup windows in userform

I have setup a userform1 to browse an intranet using web browser controls in VBA/Excel. The problem I am having is that when the user initiates a popup through the web browser control, that popup runs in IE by default, outside of the scope of the web browser control, and therefore doesnt contain the correct session data in the popup. This popup initiates from a dropdown box, onchange command and then inserts the input from the popup back into a web form on the page. The code below intercepts the popup event and lets you handle it, by transferring it to say, userform2
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim frm As UserForm2
'Dim ppDisp As Object
Set frm = New UserForm2
Set ppDisp = frm.WebBrowser1.Application
frm.Show
End Sub
Problem is, it gets stuck right now on frm.show, when I pause, and doesnt seem to be actively transferring over the web page correctly into userform2. I'm not sure where my logic is wrong here, any advice would be helpful. Most guides have shown:
Set ppDisp = frm.WebBrowser1.object
But I cant find that in the object browser anywhere, and doing .object bombs out, as error 438: object doesnt support this property or method. But everything I could find on this so far shows using .object.
for anyone reading this, VBA wont support this method as the above says. It works perfectly in .net and I would assume then, vb6

Change target of links in WebBrowser control

Sometimes when I click on a link, it opens in a new window. Can I prevent this from happening and just load the page in my current window?
This is working for me (so far):
Private Sub browser_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles browser.NewWindow
e.Cancel = True
browser.Navigate(browser.StatusText)
End Sub
Really simple, if the status text is the url (which it always is for the documents I am browsing)
If you are targeting Windows XP SP2 or later, you can catch the NewWindow3 event to get the target url, and after setting the cancel parameter, navigate to the url instead.
For earlier versions of IE you can catch the obsolete NewWindow event with the same handling as documented in Q185538 How To Cause Navigation to Occur in Same WebBrowser Window

Disabling Close window option in windows 7

My application is in VB.net with 3.5 framework. I want to disable the close button ("[X]") on the main form of the application while doing some processing.
I have achieved the disabling by overriding the "ReadOnly Property CreateParams()" of the form. This is working fine, as both the control button on the form and close option on right click in the taskbar shows them as disabled.
This fulfills my needs on Windows XP but not on Windows 7. In Windows 7, right clicking on the application icon in the TaskBar shows a different menu...which has a new "Close window" option.
Close in the original menu still shows it as disabled (this old menu is hidden, but can be shown by holding Shift key and right click on the application icon in TaskBar). Now I need to disable this "Close window" option as well...and only for my application.
Is there a method for doing this programmatically?
Use:
Private Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
End Sub
Edit:
Yes, you should check the e.CloseReason property. The sender's type is another parameter you can key off of to decide whether to cancel the close request or not.

How to determine URL about to be opened by the NewWindow event?

I'm trying to build a simple desktop application to keep users on a certain website. It's very simple, just a webbrowser control with right click disabled. However certain applications on our website require popup windows and those windows always open up a full browser window.
Private Sub WebBrowser1_NewWindow(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
'What will the URL of this new window be?
Console.WriteLine("New Window maybe to " & WebBrowser1.Url.AbsoluteUri)
End Sub
Catching the newwindow event seems straight forward, but the event does not specify the URL that is being passed to the new window. I have seen some mention of a "NewWindow2" event, but vb.net does not appear to have anything like that.
How can I get the URL that is about to be opened in a new window?
The link is generated from a normal web application and not through a webbrowser.navigate call so it could be just about anything.
Thank you
You can catch the NewWindow2 event, create a new browser instance, host it in a new form or tab and pass it to ppDisp, then handle BeforeNavigate2 to get the new url. You can cancel the navigation if necessary. See Handle the BeforeNavigate2 event in the new window to get the url. for details.