Exercice Visual Basic : Réalisation d'un Navigateur
Rédigé par GC Team, Publié le 07 Janvier 2012, Mise à jour le Samedi, 17 Décembre 2022 16:28![](/images/thumb/146/default.png)
Participez au vote ☆☆☆☆☆★★★★★
Ecrire le programme qui permet de réaliser un Navigateur.
Interface Graphique:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
Imports System.IO Public Class Form1 Private Const BLOCK_DEFAULT As String = "[DEFAULT]" Private Const BLOCK_INTERNETSHORTCUT As String = "[InternetShortcut]" Private Const ITEM_URL As String = "URL=" Private Const ITEM_BASEURL As String = "BASEURL=" Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged 'Dim DE As String 'DE = ComboBox1.Text ''ComboBox1.Items.Add("www.google.com") 'ComboBox1.Items.Add(DE) WebBrowser1.Navigate(ComboBox1.Text) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.Add("www.exercicegratuit.com") ComboBox1.Items.Add("madiha4.e-monsite.com") ComboBox1.Items.Add("naziha.forumactif.com") ComboBox1.Items.Add("www.google.com") ComboBox1.Items.Add("www.menara.ma") ComboBox1.Items.Add("www.youtube.com") ComboBox1.Items.Add("www.altavesta.com") ComboBox1.Items.Add("www.msdn.com") ComboBox1.Items.Add("www.yahoo.fr") ComboBox1.Items.Add("video.google.com") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click WebBrowser1.Navigate(ComboBox1.Text) End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted With ProgressBar1 .Minimum = 1 .Maximum = 10000 .Value = 1 .Step = 1 ProgressBar1.Visible = True For i As Integer = .Minimum To .Maximum .PerformStep() Next i End With If WebBrowser1.ReadyState Then ProgressBar1.Visible = False End If 'end of progress bar End Sub Private Sub Précédents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Précédents.Click WebBrowser1.GoBack() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click WebBrowser1.GoForward() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click WebBrowser1.GoHome() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click WebBrowser1.GoSearch() End Sub Private Sub EnregistrerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregistrerToolStripMenuItem.Click SaveFileDialog1.InitialDirectory = Application.ExecutablePath SaveFileDialog1.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*" SaveFileDialog1.FilterIndex = 0 If SaveFileDialog1.ShowDialog() = DialogResult.OK Then Dim nomFichier As String = SaveFileDialog1.FileName Dim fichier As StreamWriter = Nothing Try fichier = New StreamWriter(nomFichier) Catch ex As Exception MessageBox.Show("Problème à l'écriture du fichier (" + ex.Message + ")", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Finally Try fichier.Close() Catch End Try End Try End If End Sub Private Sub EnregestrerSousToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregestrerSousToolStripMenuItem.Click Dim save As New SaveFileDialog Dim myStreamWriter As System.IO.StreamWriter save.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*" save.CheckPathExists = True 'save.FileName = webMain.DocumentTitle save.ShowDialog(Me) Try myStreamWriter = System.IO.File.CreateText(save.FileName) myStreamWriter.Write(BLOCK_DEFAULT & vbCrLf & ITEM_BASEURL & vbCrLf & BLOCK_INTERNETSHORTCUT & vbCrLf & ITEM_URL) myStreamWriter.Flush() Catch ex As Exception ' Do nothing on Exception End Try End Sub Private Sub PagePrécédenteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PagePrécédenteToolStripMenuItem.Click WebBrowser1.GoBack() End Sub Private Sub PageSuivanteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PageSuivanteToolStripMenuItem.Click WebBrowser1.GoForward() End Sub Private Sub HomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeToolStripMenuItem.Click WebBrowser1.GoHome() End Sub Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click End End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click WebBrowser1.Navigate("www.google.com") End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged ComboBox2.Items.Add(ComboBox2.Text) End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click WebBrowser1.Navigate("http://www.google.fr/search?sourceid=navclient&hl=fr&ie=UTF-8&rlz=1T4ADBF_frMA313MA313&q=" & ComboBox2.Text) End Sub Private Sub ChercherToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChercherToolStripMenuItem.Click WebBrowser1.GoSearch() End Sub Private Sub ToolStripTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Click ToolStripTextBox1.Text = ComboBox1.Text End Sub Private Sub FenêtreToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FenêtreToolStripMenuItem.Click Form3.Show() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click WebBrowser1.Navigate("http://avg.urlseek.vmn.net/search.php?lg=en&mkt=en&type=dns&tb=ie&tbn=") End Sub Private Sub OuvrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OuvrirToolStripMenuItem.Click Dim open As New OpenFileDialog Dim URLFile As String() Dim myStreamReader As System.IO.StreamReader open.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*" open.CheckFileExists = True open.ShowDialog(Me) Try open.OpenFile() myStreamReader = System.IO.File.OpenText(open.FileName) URLFile = myStreamReader.ReadToEnd().Split(New String() {ControlChars.CrLf}, StringSplitOptions.RemoveEmptyEntries) For Each Item As String In URLFile If Item.StartsWith(ITEM_URL) Then WebBrowser1.Navigate(Item.Substring(ITEM_URL.Length)) Exit For End If Next Catch ex As Exception ' Do nothing on Exception End Try End Sub Private Sub CopierToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopierToolStripMenuItem.Click End Sub End Class |