webBrowser en VB
webBrowser en VS
Para integrar un navegador a una aplicación en Visual studio (VB o C#) primero creamos el formulario y luego se agrega el control webBrowser a la aplicación, esto desde las herramientas del formularioluego en mi caso al diseño del form le agrego un Textbox, un Timer, un Label y 5 botones tal como se muestra
en las propiedades del form1 modificamos estas partes
y para el control Webbrowser se modifica en las propiedades lo siguiente
y ahora el código para el Form1 en Visual basic
PublicClass Form1
PrivateSub Bir_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesBir.Click
IfTextBox1.Text.Trim() <> String.Empty Then
If Not TextBox1.Text.Trim().ToLower().StartsWith("http://") Then
TextBox1.Text = "http://" & TextBox1.Text.Trim()
EndIf
End If
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Batras_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesBatras.Click
WebBrowser1.GoBack()
End Sub
Private Sub Badelante_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesBadelante.Click
WebBrowser1.GoForward()
End Sub
Private Sub Bactualizar_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesBactualizar.Click
WebBrowser1.Refresh()
End Sub
Private Sub Bdetener_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesBdetener.Click
WebBrowser1.Stop()
End Sub
Private Sub Binicio_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesBinicio.Click
WebBrowser1.Navigate("www.pabletoreto.blogspot.com")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender AsSystem.Object, ByVale As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
TextBox1.Text = WebBrowser1.Url.AbsoluteUri
End Sub
Private Sub Form1_Load(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesMyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByValsender As System.Object, ByVal e AsSystem.EventArgs) HandlesTimer1.Tick
Label1.Text = WebBrowser1.StatusText
End Sub
Private Sub TextBox1_KeyPress(ByValsender As Object, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Ife.KeyChar = ChrW(Keys.Enter) Then
e.Handled = True
WebBrowser1.Navigate(TextBox1.Text)
End If
End Sub
EndClass
y para C# este sería el código
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
public partial class Form1 : Form
{
publicForm1()
{
InitializeComponent();
}
privatevoid bir_Click(objectsender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text);
}
privatevoid batras_Click(objectsender, EventArgs e)
{
webBrowser1.GoBack();
}
privatevoid badelante_Click(objectsender, EventArgs e)
{
webBrowser1.GoForward();
}
privatevoid bactualizar_Click(objectsender, EventArgs e)
{
webBrowser1.Refresh();
}
privatevoid Detener_Click(objectsender, EventArgs e)
{
webBrowser1.Stop();
}
privatevoid binicio_Click(objectsender, EventArgs e)
{
webBrowser1.Navigate("www.pabletoreto.blogspot.com");
}
privatevoid webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgse)
{
textBox1.Text = webBrowser1.Url.AbsoluteUri;
}
privatevoid Form1_Load(objectsender, EventArgs e)
{
timer1.Start();
}
privatevoid timer1_Tick(objectsender, EventArgs e)
{
label1.Text = webBrowser1.StatusText;
}
privatevoid textBox1_KeyPress(objectsender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)(Keys.Enter))
{
e.Handled = true;
webBrowser1.Navigate(textBox1.Text);
}
}
}
}
COMENTA LA PUBLICACION