13/03/09 18:15
Il Totem
Basta usare una variabile globale che contenga un riferimento al browser di volta in volta selezionato...
aaa
13/03/09 20:06
raf_lele
Ho fatto così ma non va mi puoi aiutare con il codice???grz...
Private Sub WebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles WebBrowser1.NewWindow2 Dim frmWB As Form1 frmWB = New Form1() frmWB.WebBrowser1.RegisterAsBrowser = True e.ppDisp = frmWB.WebBrowser1.Application frmWB.Visible = True End Sub Private Sub WebBrowser2_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles WebBrowser2.NewWindow2 Dim frmWB As Form1 frmWB = New Form1() frmWB.WebBrowser2.RegisterAsBrowser = True e.ppDisp = frmWB.WebBrowser2.Application frmWB.Visible = True End Sub Private Sub WebBrowser3_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles WebBrowser3.NewWindow2 Dim frmWB As Form1 frmWB = New Form1() frmWB.WebBrowser3.RegisterAsBrowser = True e.ppDisp = frmWB.WebBrowser3.Application frmWB.Visible = True End Sub
aaa
15/03/09 16:40
Il Totem
Non hai seguito il mio consiglio. Ti avevo detto di usare una variabile globale:
Che cambi quando cambi tab:
E poi gestisci l'evento di quell'oggetto:
Class Form1 Private WithEvents CurrentWebBrowser As AxWebBrowser '... End Class
Che cambi quando cambi tab:
Dim Selected As TabPage = TabControl.SelectedTab 'Presumo che in una tab ci sia solo il web browser, 'perciò mi riferisco ad asso come il primo (ed unico) 'controllo della tab CurrentWebBrowser = Selected.Controls(0)
E poi gestisci l'evento di quell'oggetto:
Private Sub CurrentWebBrowser_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles CurrentWebBrowser.NewWindow2 Dim frmWB As Form1 frmWB = New Form1() frmWB.AxWebBrowser1.RegisterAsBrowser = True e.ppDisp = frmWB.AxWebBrowser1.Application frmWB.Visible = True End Sub
aaa
18/03/09 15:30
raf_lele
Public Class Form1 Private WithEvents CurrentWebBrowser As AxSHDocVw.AxWebBrowser Private Sub CurrentWebBrowser_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Select Case TabControl1.SelectedIndex.ToString() Case 0 CurrentWebBrowser = aWebBrowser1 Case 1 CurrentWebBrowser = WebBrowser2 Case 2 CurrentWebBrowser = WebBrowser3 End Select Dim frmWB As Form1 frmWB = New Form1() frmWB.aWebBrowser1.RegisterAsBrowser = True e.ppDisp = frmWB.aWebBrowser1.Application frmWB.Visible = True End Sub Private Sub AggiungiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AggiungiToolStripMenuItem.Click Dim STRLINE As String Dim FILEREADER As System.IO.StreamReader Dim response As MsgBoxResult If TextBox1.Text = "" Then Exit Sub End If FILEREADER = New System.IO.StreamReader(Application.StartupPath & "\" & "preferiti.txt") STRLINE = FILEREADER.ReadToEnd While STRLINE <> Nothing STRLINE = FILEREADER.ReadToEnd If STRLINE = TextBox1.Text Then MsgBox("Il sito " + TextBox1.Text + "è già presente nella lista dei preferiti") FILEREADER.Close() FILEREADER = Nothing Exit Sub End If End While FILEREADER.Close() FILEREADER = Nothing response = MsgBox("Desideri inserire il sito " + TextBox1.Text + " nella lista dei preferiti?", MsgBoxStyle.YesNo) If response = 6 Then Dim FileWriter As New System.IO.StreamWriter(Application.StartupPath & "\" & "preferiti.txt", True) FileWriter.Write(vbCrLf + TextBox1.Text) FileWriter.Close() FileWriter = Nothing Else Exit Sub End If End Sub
Ho un piccolo problema anke con i preferiti se gli dico di non aggiungere un sito già presente nella lista lo aggiunge lo stesso...Come posso risolvere??? Aiutooo
aaa
20/03/09 17:04
Il Totem
1. Dal momento che CurrentWebBrowser all'inizio è Nothing, se tu non lo reimposti prima, rimarrà sempre Nothing e quindi non produrrà eventi. Lo devi impostare nell'evento SelectedTabChanged (o una cosa simile) del TabControl.
2. Hai usato FILEREADER.ReadToEnd() invece che ReadLine().
2. Hai usato FILEREADER.ReadToEnd() invece che ReadLine().
aaa