Hey,
Using the WebBrowser control how do you make it so that a textbox always has the URL you are at in it
like if I was to make the default URL of the WebBrowser www.google.com
and then the program is run, but the textbox dose not automaticly have
the Url in it...How would I make it so the Url is always in the textbox
Thanks :)

WebBrowser URL
AnnabelP
Umm, your code has alot of errors
and the Ax stuff...
incase you need this stuff:
webbrowser: webBrowser1
Url textbox: URLtextbox
Do you have to put every bit of code in it
and I kinda figured axwebbrowser is the name of the webbrowser, so I think I got that part...
Before I tryed doing this in a timer that counted every second:
WebBrowser thiswebpage = GetCurrentWebBrowser();
URLtextbox.Text = thiswebpage.Document.Url;but that gets an error saying that it can't convert thiswebpage.Document.Url into a string...like this: Can not implicitly convert type 'System.Uri' to 'String'
Thanks :)
jcnewbie
Don Tran
this.textBox1.Text = "http://www.google.com";
this.axWebBrowser1.Navigate(this.textBox1.Text);
private void axWebBrowser1_NavigateComplete2
private void axWebBrowser1_StatusTextChange
SOURCE
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication4
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.textBox1.Text = "http://www.google.com";
this.axWebBrowser1.Navigate(this.textBox1.Text);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
this.SuspendLayout();
//
// axWebBrowser1
//
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.Location = new System.Drawing.Point(8, 40);
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(440, 150);
this.axWebBrowser1.TabIndex = 0;
this.axWebBrowser1.StatusTextChange += new AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler(this.axWebBrowser1_StatusTextChange);
this.axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 8);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(440, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 200);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(440, 23);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(456, 230);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.axWebBrowser1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
this.textBox1.Text = e.uRL.ToString();
}
private void axWebBrowser1_StatusTextChange(object sender, AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e)
{
this.label1.Text = e.text.ToString();
}
}
}
M Eslinger
Is there a way I can use these things instead so it is less code :
WebBrowser
thiswebpage = GetCurrentWebBrowser();and also use:
thiswebpage.Document.Url
GetCurrentWebBrowser is a refactor,
and this all that's in it:
TabPage current_tab = tabControl1.SelectedTab; WebBrowser thiswebpage = (WebBrowser)webpages[tabpages.IndexOf(current_tab)]; return thiswebpage;Thanks:)
devexpert
It's not quite fully automatic... but try subscribing to the Navigating event and use the Uri property of the WebBrowserNavigatingEventArgs you receive in your handling function.
52179apb
thiswebpage.Document.Url.ToString(); // remove
URLtextbox.Text = thiswebpage.Document.Url.ToString(); //Try
hairunizam
DownloadCompleted() event is where you set the textbox.Text. The event should give you the URL it's currently on.
StatusFeedback() - *or something like that, is the event you use to display the same information that you see on the status bar of IE. The event should give you the Text property for the current status.
Robert Reister
you mean like this
private void timer2_Tick(object sender, EventArgs e){
WebBrowser thiswebpage = GetCurrentWebBrowser();thiswebpage.Document.Url.ToString();
URLtextbox.Text = thiswebpage.Document.Url;
}
or in your code
Thanks :)
clear_zero
hmmm, nope, it did not work, I tryed a few other things in the list to with that, navigated and navigating, but those did not work...
Is there mabee somthign about the webbrowser control that is making this not work
I am using tabs, so you can have more then one website open at the same time, could that be interfering Becuase I know that the tab names work(the title of the webpage is the text on the tab), and they always stay updated...wait, I think I ahve an idea, mabee in the part where it changes the tab names, I could also try and put in the
this.URLtextbox.Text = e.Url.ToString();
and see if that works,hold on I am gunna try it.
Thanks :)
EDIT:
nope it problably would have worked but there was a problem with e..., this si the code for updating the tab text:
private void UpdateName(TabPage tb){
// Update the name of the current tab by looking // at the document it is displayed TabPage current_tab = tb; WebBrowser thiswebpage = (WebBrowser)webpages[tabpages.IndexOf(current_tab)]; if (thiswebpage.Document != null){
current_tab.Text = thiswebpage.Document.Title;
}
elsecurrent_tab.Text =
"...";}
If I added
this
.URLtextbox.Text = e.Url.ToString(); aftercurrent_tab.Text = thiswebpage.Document.Title;
then I get an error about e dose not exist, and thta is becuase in
private void UpdateName(TabPage tb)
there is no e, I tryed putting a , after tb and then e but that did not work(error), and I tryed doing tb.Url.ToString(); but .Url was not valid with tb, so that did not work...any suggestions
EDIT2:Wait, I found the problem, there was a Document Compleeted already created by itself, not under properties so thats why it would not work, I found the other one and put it in there, it works now, Thanks :)
Randal Greene
Becuase I am a little confused on how I would use it to make it work...
Thanks :)
Tim Wong
Sorry I didn't read your signature, ax.. thingy is introduced in VS2003 as a wrapper to pre-.NET activex, so the activex can be used in VS .NET.
Try this thiswebpage.Document.Url.ToString()
rivast_2001
I'm still trying to figure out what's the exquivalent of StatusTextChange in Express, but DocumentCompleted should tell you the current URL you are in. If you include this event the textbox should always display the URL you are in.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){
this.textBox1.Text = e.Url.ToString();}
SHakeelGhauri77