vb.net webbrowser navigate to url contained in richtextbox - vb.net

I have a richtextbox that contains URLs and a webborwser and a button. I would like that everytime i press the button, my webbrowser navigate to each url (one URL by line).
Here is my code :
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For i As Integer = 0 To RichTextBox1.Lines.Count - 1
WebBrowser1.Navigate(RichTextBox1.Lines(i))
Next
End Sub
My problem : It seems that the webbrowser navigate directly (cause other URL are loaded too fast) to the last website contained in the richtextbox...
How can i ask my webbrowser to wait the button to be clicked to navigate to the next URL ?

Public Shared i As Integer = 0
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
WebBrowser1.Navigate(RichTextBox1.Lines(i))
i = i + 1
End Sub
thanks again #jmcilhinney

Related

How do I login Via a Button using VB and a Web Browser Element

I've added a web browser element to my form and have been able to enter information into the box. When entering the correct information the webpage tries to download, how do I stop this from happening?
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim usernameTextBox As HtmlElement = Me.WebBrowser1.Document.All.Item("Email")
usernameTextBox.InnerText = "******"
Dim passwordTextBox As HtmlElement = Me.WebBrowser1.Document.All.Item("Password")
passwordTextBox.InnerText = "******"
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(New Uri("https://squareup.com/terminal/"))
End Sub
End Class
The output tries to download the webpage Image

finding web page source at desired instance VB.NET

IN CODE: At 1 browser clicks a button and takes a time to load. AT 2 i get source code of page in RichTextBox1. but as page take time to load code 2 starts before completion of 1 because of that i am unable to get the web page source at desired state? what do i do ? i want to get web page source when web browser completely loads after the execution of code 1.
i have tried
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WebBrowser1.Navigate("some website")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("notification_address").SetAttribute("value", TextBox1.Text)
WebBrowser1.Document.Forms(0).InvokeMember("submit") (-----1-----)
RichTextBox1.Text = WebBrowser1.DocumentText (-----2-----)
End Sub
You can use the DocumentCompleted event.
https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
Private Sub DocumentCompleted(ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
' this is where your code goes RichTextBox1.Text = WebBrowser1.DocumentText (-----2-----)
End Sub

VB.NET Create a to a form attached Preview window

I want to create a little window which gets visible when I press a button and is attached to the main Form (like shwon below). I want to use this window to show preview of Images (I gonna have a Listbox and depending on which entry is selected, a picture is shown) How can I do this? And how can I be sure that the window will always be attached to the main Form (not depending on resolution). I tried to do it with a second form, but I can't fix it in the correct position.
regards
Assuming your preview form class is frmPreview and you open it this way:
Private mPreviewForm As frmPreview
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
mPreviewForm = New frmPreview
mPreviewForm.Show()
AttachPreviewForm()
End Sub
Then you must reposition it every time the main form is changing size or location:
Private Sub AttachPreviewForm()
If mPreviewForm IsNot Nothing Then
mPreviewForm.AttachForm(Me)
End If
End Sub
Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
AttachPreviewForm()
End Sub
Private Sub Form1_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged
AttachPreviewForm()
End Sub
And in the frmPreview:
Public Sub AttachForm(parent As Form)
Location = New Point(parent.Left + parent.Width, parent.Top)
Size = New Size(200, parent.Height)
End Sub

WebBrowser load and display URLs from file

I want to load a list of URLs in a text file. I have done that using a For Each loop, but I want the browser to load the page first fully before going to the next URL. Here is my code:
For Each url in File.ReadAllLines("urls.txt")
Browser.Navigate(url)
Next
It doesn't display anything. I tried using:
Do While Browser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
It displays the page but the first line is the only one being loaded.
If you want to navigate to each URL after the other you are better of storing all of them in a class level array and subscribing to the WebBrowser.DocumentCompleted event, then keep track of which URL index you're currently at via a class level Integer variable.
When the DocumentCompleted event is raised you just increment the integer variable and load the URL from the next item of the array.
Public Class Form1
Dim URLs As String()
Dim UrlIndex As Integer = 0
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
URLs = File.ReadAllLines("urls.txt")
WebBrowser1.Navigate(URLs(UrlIndex))
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
UrlIndex += 1
If UrlIndex >= URLs.Length Then
UrlIndex = 0 'Go back to the beginning.
End If
WebBrowser1.Navigate(URLs(UrlIndex))
End Sub
End Class
To add a delay to it to make each URL show for a little while you can use a Timer (Credit to Werdna for bringing up the subject):
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
UrlIndex += 1
If UrlIndex >= URLs.Length Then
UrlIndex = 0 'Go back to the beginning.
End If
WebBrowser1.Navigate(URLs(UrlIndex))
Timer1.Stop()
End Sub
Just set the timer's Interval property to change how long a site should be displayed (in milliseconds).

How to send an image through the Skype API?

I am using the Skype4ComLib library to try and send an image to a contact on Skype.
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles btnImageLoad.Click
OpenFileDialog1.ShowDialog()
PicBox.ImageLocation = OpenFileDialog1.FileName.ToString
End Sub
This opens a dialog box for the user to select an image and loads it into a picture box called PicBox.
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
TimerImage.Stop()
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button16.Click
TimerImage.Stop()
End Sub
Buttons 15 and 16 start the timer.
I want to send the image from within the timer but I can't use skype.sendmessage as it only accepts a string.
Any ideas?
Using the SendKeys.Send method you can paste the picture from the clipboard in the message via the actual Skype application.
This is how I do it:
My.Computer.Clipboard.SetImage(PicBox.Image)
SkypeClient.Client.OpenMessageDialog("<contact to send to>")
SkypeClient.Client.Focus()
SendKeys.Send("^(V){ENTER}")
Replace <contact to send to> with the name of the contact you want to send the picture to.