Besoin daide favorie webrowser(ajouter toolstripmenuitem a laide d un boutton

daval43 Messages postés 49 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 14 septembre 2012 - 22 nov. 2011 à 10:05
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 - 24 nov. 2011 à 00:16
bonjour je suis debutant en vb et je me suis fait un webrowser ...mais je sais pas comment faire un onglet Favori (qui comprend un boutton ajouter, un textboxt pour inscrire le lien a ajouter ex www.google.com)et par la fin mon toolstripmenuitem (renomer ex www.google.com)

voila se que je veut faire
(textboxt) jecrit www.google.com
je click sur mon boutton ajouter
et sa m'ajoute ca avec le meme code
Private Sub www.google.comToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles www.google.comToolStripMenuItem.Click

        Actions.CreerUneNouvelleFenetre()
        ActiveWebBrowser.Navigate("www.google.com")
    End Sub

ensuite je veut que sa sauvegarde automatiquement

jais esailler des ta de chose mais sa na rien donner merci de maider
se que je veut dire en image

3 réponses

ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
22 nov. 2011 à 11:38
Bonjour daval n°43,

Oh, je crois, qu'il faut une gstion complète de fichier, c'est-à-dire d'enregistrer avec ton add dans un fichier texte, puis quand tu veux affichier les favoris, de lire ce fichier pour les mettre dans une liste, un menu-liste, car suffit pas de faire "add", faut bien que ton lien soit casé quelque par pour être rappelé... Et si tu veux renommer, il vaudrait mieux rajouter une form ou tu ferais la gestion de tes liens de favoris pour que ce soit clair.

Il pouraît te venir à l'idée d'utiliser le menu favoris de l'IE9, mais ce ne serait pas obligatoirement une bonne idée car souvent les modifications apportés sur les éléments liés au WenWrowser sont directement répercutés sur ceux de l'IE, et après il y aurait un risque de mauvais fonctionnement...

Si tu ne sais pas faire tout ça, ben taka repasser s'il y a de la lumière, on te fera (enfin, pas toi, mais le programme).
Toutefois, si tu es débutant, tu mets le niveau un peu haut pour commencer... à toi de voir si tu suivras...

Justement, je suis en train de faire en ce moment une menu de gestion des favoris d'un WebBrowser, voici ci-joint le code, mais attention il est en construction, ça donne juste une idée de la façon dont je m'y prends, façon encore plus compliquée car je gère dans le même fichier texte les liens Net et les liens Mails que j'utiliserai dans une autre fonction sur un autre form...


'
' aide vbnet form3 appel de forums
Option Explicit On
Public Class Form3
  Dim liens As String

  Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Top = Form1.Top + 40
    Me.Left = Form1.Left + 30
    Call lit()
  End Sub

  Sub AideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AideToolStripMenuItem.Click
    Dim m As String
    Dim s As String = vbLf
    m = "Aide" & s & s
    m m & "Appeler un forum Double-cliquer sur le lien" & s & s
    m m & "Supprimer un lien (Sélectionner la ligne préalablement)" & s & s
    m = m & "Fichier à sauvegarder : vbnetAideLiens.txt" & s
    MsgBox(m, vbInformation)
  End Sub

  Sub AjouterUnLienToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AjouterUnLienToolStripMenuItem.Click
    Dim r As String
    Dim er As Byte = 1
    Dim i As Integer
    r = InputBox("Saisir le nouveau lien ?  ")
    r = Trim(r)
    If r = "" Then Exit Sub
    r = LCase(r)
    If Len(r) < 12 Then GoTo erreur
    er = 2
    If Mid(r, 1, 7) <> "http://" Then GoTo erreur
    er = 3
    i = InStr(1, r, ".", 1)
    If i = 0 Then GoTo erreur
    er = 4
    For i = 0 To ListBox1.Items.Count - 1
      If r = ListBox1.Items(i) Then GoTo erreur
    Next i
    ListBox1.Items.Add(r)
    Call ecrit()
    Call lit()
    Exit Sub
erreur:
    r = "ERREUR DE SAISIE" & vbLf & vbLf
    Select Case er
      Case 1 : r = r & "Lien trop court"
      Case 2 : r = r & "Début de lien non conforme"
      Case 3 : r = r & "Fin de lien sans domaine"
      Case 4 : r = r & "Lien déjà existant"
    End Select
    MsgBox(r & vbLf, vbExclamation)
  End Sub

  Sub lit()
    Dim ligne As String
    Dim i As Integer
    Try
      ListBox1.Items.Clear()
      ListBox2.Items.Clear()
      ListBox3.Items.Clear()
      Dim p As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
      While p.Peek() >= 0
        ligne = p.ReadLine()
        If Mid(ligne, 1, 7) = "http://" Then
          ListBox2.Items.Add(ligne)
        Else
          ListBox3.Items.Add(ligne)
        End If
      End While
      p.Close()
    Catch ex As Exception
      Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
      p1.Close()
    End Try
    For i = 0 To ListBox2.Items.Count - 1
      ListBox1.Items.Add(ListBox2.Items(i))
    Next i
    Dim p2 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
    For i = 0 To ListBox2.Items.Count - 1
      p2.WriteLine(ListBox2.Items(i))
    Next i
    For i = 0 To ListBox3.Items.Count - 1
      p2.WriteLine(ListBox3.Items(i))
    Next i
    p2.Close()
    Call nombreDeLiens()
  End Sub

  Sub ecrit()
    Dim p As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
    For i = 0 To ListBox1.Items.Count - 1
      p.WriteLine(ListBox1.Items(i))
    Next i
    For i = 0 To ListBox3.Items.Count - 1
      p.WriteLine(ListBox3.Items(i))
    Next i
    p.Close()
  End Sub

  Sub nombreDeLiens()
    liens "Nombre de liens " & ListBox1.Items.Count
    If ListBox1.Items.Count < 2 Then liens "Nombre de lien " & ListBox1.Items.Count
    NombreDeLiensToolStripMenuItem.Text = liens
  End Sub

End Class



Cordialement, Joe.
0
daval43 Messages postés 49 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 14 septembre 2012
23 nov. 2011 à 23:16
Serieusement merci beaucoup jais utiliser ton bout de code et je lais modifier comme ceci
     Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Top = frm_PRINCIPAL.Top + 40
        Me.Left = frm_PRINCIPAL.Left + 30
        Call lit()
    End Sub

    Sub AideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AideToolStripMenuItem.Click
        Dim m As String
        Dim s As String = vbLf
        m = "Aide" & s & s
        m m & "Appeler un forum Double-cliquer sur le lien" & s & s
        m m & "Supprimer un lien (Sélectionner la ligne préalablement)" & s & s
        m = m & "Fichier à sauvegarder : vbnetAideLiens.txt" & s
        MsgBox(m, vbInformation)
    End Sub

    Sub AjouterUnLienToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AjouterUnLienToolStripMenuItem.Click
        Dim r As String
        Dim er As Byte = 1
        Dim i As Integer
        r = InputBox("Saisir le nouveau lien ?", , "http://")
        r = Trim(r)
        If r = "" Then Exit Sub
        r = LCase(r)
        If Len(r) < 12 Then GoTo erreur
        er = 2
        If Mid(r, 1, 7) <> "http://" Then GoTo erreur
        er = 3
        i = InStr(1, r, ".", 1)
        If i = 0 Then GoTo erreur
        er = 4
        For i = 0 To ListBox1.Items.Count - 1
            If r = ListBox1.Items(i) Then GoTo erreur
        Next i
        ListBox1.Items.Add(r)
        Call ecrit()
        Call lit()
        Exit Sub
erreur:
        r = "ERREUR DE SAISIE" & vbLf & vbLf
        Select Case er
            Case 1 : r = r & "Lien trop court"
            Case 2 : r = r & "Début de lien non conforme. Veuillez ajouter http:// a votre lien"
            Case 3 : r = r & "Fin de lien sans domaine"
            Case 4 : r = r & "Lien déjà existant"
        End Select
        MsgBox(r & vbLf, vbExclamation)
    End Sub

    Sub lit()
        Dim ligne As String
        Dim i As Integer
        Try
            ListBox1.Items.Clear()
            ListBox2.Items.Clear()
            Dim p As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
            While p.Peek() >= 0
                ligne = p.ReadLine()
                If Mid(ligne, 1, 7) = "http://" Then
                    ListBox2.Items.Add(ligne)

                End If
            End While
            p.Close()
        Catch ex As Exception
            Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
            p1.Close()
        End Try
        For i = 0 To ListBox2.Items.Count - 1
            ListBox1.Items.Add(ListBox2.Items(i))
        Next i
        Dim p2 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
        For i = 0 To ListBox2.Items.Count - 1
            p2.WriteLine(ListBox2.Items(i))
        Next i
        p2.Close()
    End Sub

    Sub ecrit()
        Dim p As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
        For i = 0 To ListBox1.Items.Count - 1
            p.WriteLine(ListBox1.Items(i))
        Next i
      p.Close()
    End Sub

    Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick

        Actions.CreerUneNouvelleFenetre()
        ActiveWebBrowser.Navigate(ListBox1.SelectedItem) 
jais aussi utiliser ton code pour faire un onglet historique encore une fois merci!
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
24 nov. 2011 à 00:16
Bonsoir dava n°l43,

Contents de t'avoir été utile, voici le code au complet cette fois (suite après) :


'
' aide vbnet form3 appel de forums
Option Explicit On
Public Class Form3
  Dim liens As String

  Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Top = Form1.Top + 40
    Me.Left = Form1.Left + 30
    Call lit()
  End Sub

  Sub AideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AideToolStripMenuItem.Click
    Dim m As String
    Dim s As String = vbLf
    m = "Aide" & s & s
    m m & "Appeler un forum Double-cliquer sur le lien" & s & s
    m m & "Supprimer un lien (Sélectionner la ligne préalablement)" & s & s
    m = m & "Fichier à sauvegarder : vbnetAideLiens.txt" & s
    MsgBox(m, vbInformation)
  End Sub

  Sub AjouterUnLienToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AjouterUnLienToolStripMenuItem.Click
    Dim r As String
    Dim er As Byte = 1
    Dim i As Integer
    r = InputBox("Saisir le nouveau lien ?  ")
    r = Trim(r)
    If r = "" Then Exit Sub
    r = LCase(r)
    If Len(r) < 12 Then GoTo erreur
    er = 2
    If Mid(r, 1, 7) <> "http://" Then GoTo erreur
    er = 3
    i = InStr(1, r, ".", 1)
    If i = 0 Then GoTo erreur
    er = 4
    For i = 0 To ListBox1.Items.Count - 1
      If r = ListBox1.Items(i) Then GoTo erreur
    Next i
    ListBox1.Items.Add(r)
    Call ecrit()
    Call lit()
    Exit Sub
erreur:
    r = "ERREUR DE SAISIE" & vbLf & vbLf
    Select Case er
      Case 1 : r = r & "Lien trop court"
      Case 2 : r = r & "Début de lien non conforme"
      Case 3 : r = r & "Fin de lien sans domaine"
      Case 4 : r = r & "Lien déjà existant"
    End Select
    MsgBox(r & vbLf, vbExclamation)
  End Sub

  Sub lit()
    Dim ligne As String
    Dim i As Integer
    Try
      ListBox1.Items.Clear()
      ListBox2.Items.Clear()
      ListBox3.Items.Clear()
      Dim p As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
      While p.Peek() >= 0
        ligne = p.ReadLine()
        If Mid(ligne, 1, 7) = "http://" Then
          ListBox2.Items.Add(ligne)
        Else
          ListBox3.Items.Add(ligne)
        End If
      End While
      p.Close()
    Catch ex As Exception
      Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
      p1.Close()
    End Try
    For i = 0 To ListBox2.Items.Count - 1
      ListBox1.Items.Add(ListBox2.Items(i))
    Next i
    Dim p2 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
    For i = 0 To ListBox2.Items.Count - 1
      p2.WriteLine(ListBox2.Items(i))
    Next i
    For i = 0 To ListBox3.Items.Count - 1
      p2.WriteLine(ListBox3.Items(i))
    Next i
    p2.Close()
    Call nombreDeLiens()
  End Sub

  Sub ecrit()
    Dim p As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
    For i = 0 To ListBox1.Items.Count - 1
      p.WriteLine(ListBox1.Items(i))
    Next i
    For i = 0 To ListBox3.Items.Count - 1
      p.WriteLine(ListBox3.Items(i))
    Next i
    p.Close()
  End Sub

  Sub nombreDeLiens()
    liens "Nombre de liens " & ListBox1.Items.Count
    If ListBox1.Items.Count < 2 Then liens "Nombre de lien " & ListBox1.Items.Count
    NombreDeLiensToolStripMenuItem.Text = liens
  End Sub

  Sub SupprimerLeLienToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupprimerLeLienToolStripMenuItem.Click
    Dim r As Integer
    If ListBox1.Items.Count < 1 Or ListBox1.SelectedIndex < 0 Then Exit Sub
    r = MsgBox("Supprimer : " & vbLf & vbLf & ListBox1.Items(ListBox1.SelectedIndex), vbQuestion + vbYesNo + vbDefaultButton2)
    If r <> vbYes Then Exit Sub
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    Call ecrit()
    Call lit()
  End Sub

  Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    If ListBox1.Items.Count < 1 Then Exit Sub
    Try
      Process.Start(ListBox1.Items(ListBox1.SelectedIndex))
    Catch ex As Exception
      MsgBox("Impossible d'ouvrir le site ", vbExclamation,
      My.Application.Info.ProductName)
    End Try
  End Sub

End Class



-----------------


'
' aide vbnet form4 envoi mails
Option Explicit On
Public Class Form4
  Dim liens As String

  Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Top = Form1.Top + 40
    Me.Left = Form1.Left + 30
    Call lit()
  End Sub

  Sub AideToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AideToolStripMenuItem1.Click
    Dim m As String
    Dim s As String = vbLf
    m = "Aide" & s & s
    m m & "Ecrire un mail Double-cliquer sur le lien" & s & s
    m m & "Supprimer une adresse (Sélectionner la ligne préalablement)" & s & s
    m = m & "Fichier à sauvegarder : vbnetAideLiens.txt" & s
    MsgBox(m, vbInformation)
  End Sub

  Sub AjouterUneAdresseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AjouterUneAdresseToolStripMenuItem.Click
    Dim r As String
    Dim er As Byte = 1
    Dim i As Integer
    r = InputBox("Saisir la nouvelle adresse ?  ")
    r = Trim(r)
    If r = "" Then Exit Sub
    r = LCase(r)
    If Len(r) < 8 Then GoTo erreur
    er = 2
    i = InStr(1, r, "@", 1)
    If i = 0 Then GoTo erreur
    er = 3
    i = InStr(1, r, ".", 1)
    If i = 0 Then GoTo erreur
    er = 4
    For i = 0 To ListBox1.Items.Count - 1
      If r = ListBox1.Items(i) Then GoTo erreur
    Next i
    ListBox1.Items.Add(r)
    Call ecrit()
    Call lit()
    Exit Sub
erreur:
    r = "ERREUR DE SAISIE" & vbLf & vbLf
    Select Case er
      Case 1 : r = r & "Adresse trop courte"
      Case 2 : r = r & "Adresse sans arobase"
      Case 3 : r = r & "Adresse sans domaine"
      Case 4 : r = r & "Adresse déjà existante"
    End Select
    MsgBox(r & vbLf, vbExclamation)
  End Sub

  Sub lit()
    Dim ligne As String
    Dim i As Integer
    Try
      ListBox1.Items.Clear()
      ListBox2.Items.Clear()
      ListBox3.Items.Clear()
      Dim p As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
      While p.Peek() >= 0
        ligne = p.ReadLine()
        If Mid(ligne, 1, 7) = "http://" Then
          ListBox2.Items.Add(ligne)
        Else
          ListBox3.Items.Add(ligne)
        End If
      End While
      p.Close()
    Catch ex As Exception
      Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
      p1.Close()
    End Try
    For i = 0 To ListBox3.Items.Count - 1
      ListBox1.Items.Add(ListBox3.Items(i))
    Next i
    Dim p2 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
    For i = 0 To ListBox2.Items.Count - 1 ' classement dans fichier par la les listes
      p2.WriteLine(ListBox2.Items(i))
    Next i
    For i = 0 To ListBox3.Items.Count - 1
      p2.WriteLine(ListBox3.Items(i))
    Next i
    p2.Close()
    Call nombreDadresses()
  End Sub

  Sub ecrit()
    Dim p As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\vbnetAideLiens.txt"))
    For i = 0 To ListBox2.Items.Count - 1 ' liens
      p.WriteLine(ListBox2.Items(i))
    Next i
    For i = 0 To ListBox1.Items.Count - 1 ' adresses
      p.WriteLine(ListBox1.Items(i))
    Next i
    p.Close()
  End Sub

  Sub nombreDadresses()
    liens "Nombre d'adresses " & ListBox1.Items.Count
    If ListBox1.Items.Count < 2 Then liens "Nombre d'adresse " & ListBox1.Items.Count
    NombreDadressesToolStripMenuItem.Text = liens
  End Sub

  Sub SupprimerUneAdresseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupprimerUneAdresseToolStripMenuItem.Click
    Dim r As Integer
    If ListBox1.Items.Count < 1 Or ListBox1.SelectedIndex < 0 Then Exit Sub
    r = MsgBox("Supprimer : " & vbLf & vbLf & ListBox1.Items(ListBox1.SelectedIndex), vbQuestion + vbYesNo + vbDefaultButton2)
    If r <> vbYes Then Exit Sub
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    Call ecrit()
    Call lit()
  End Sub

  Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    If ListBox1.Items.Count < 1 Then Exit Sub
    Dim dest As String = ListBox1.Items(ListBox1.SelectedIndex)
    Try
      System.Diagnostics.Process.Start("mailto:" & dest)
    Catch ex As Exception
      MsgBox("Impossible d'ouvrir le gestionnaire de Mails ", vbExclamation,
      My.Application.Info.ProductName)
    End Try
  End Sub

End Class



----------- suite -------------

Ça donne une idée sur la possibilité de faire des enregistrement en rapport avec le webBrowser, toutefois si on veux faire beaucoup de dossiers pour classer les rubrique, voire à en rajouter, il faut sans doute rajouter en fin de ligne de list (invisible), le classement, et ensuite on peut déployer par exemple dans un combo les différentes rubriques, puis selon le choix afficher la liste voulue (son contenu), mais ça dépasse mon code qui n'est pas fait pour ça.

Au plaisir, cordialement, Joe.
0
Rejoignez-nous