Webbrowser problem?

Webbrowser home page and listbox

Page 1 of 1

1 Replies - 2253 Views - Last Post: 08 April 2009 - 05:14 AM Rate Topic: -----

#1 NECsync  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-April 09

Webbrowser problem?

Posted 08 April 2009 - 04:43 AM

Hello

1.Problem - Webbrowser home page
Please help me! I need to change my C# webbrowser home page when program is running but i don't know code for this!

2.Problem - listbox
I don't know how to link between two forms (Form1 and Form2) so do i have in Form1 a webbrowser in Form2 a listbox. Example:When i click button (bookmarks) in Form1, listbox in Form2 must have inserted site.

Please understand me im not speak english very well!

namespace Brskalnik_FINAL
{
	public partial class Form1 : Form
	{
		public string Home;

		public Form1()
		{
			InitializeComponent();
		}

		private void toolStripButton1_Click(object sender, EventArgs e)
		{
			webBrowser1.GoBack();
		}

		private void toolStripButton2_Click(object sender, EventArgs e)
		{
			webBrowser1.GoForward();
		}

		private void toolStripButton3_Click(object sender, EventArgs e)
		{
			webBrowser1.Stop();
		}

		private void toolStripButton4_Click(object sender, EventArgs e)
		{
			webBrowser1.Refresh();
		}

		private void toolStripButton5_Click(object sender, EventArgs e)
		{
			webBrowser1.GoHome();
		}

		private void toolStripButton6_Click(object sender, EventArgs e)
		{
			webBrowser1.Navigate(URL.Text);
		}

		private void novoOknoToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Form1 Form1 = new Form1();
			Form1.Show();
		}

		private void odpriToolStripMenuItem_Click(object sender, EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.FileName = "";
			openFileDialog.Filter = "Webpages|*.html|All Files|*.*";
			openFileDialog.Title = "Odpri spletno stran";
			if (openFileDialog.ShowDialog(this) == DialogResult.OK)
			{
				webBrowser1.DocumentText = System.IO.File.ReadAllText(openFileDialog.FileName);
			}
		}

		private void shraniToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.ShowSaveAsDialog();
		}

		private void izvornaKodaToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Form sourceForm = new Form();
			TextBox sourceCode = new TextBox();
			sourceCode.Dock = DockStyle.Fill;
			sourceCode.ReadOnly = true;
			sourceCode.BackColor = Color.White;
			sourceCode.Multiline = true;
			sourceCode.ScrollBars = ScrollBars.Both;
			sourceForm.Width = 600;
			sourceForm.Height = 400;
			sourceForm.StartPosition = FormStartPosition.CenterParent;
			sourceForm.ShowIcon = false;
			sourceForm.ShowInTaskbar = true;
			sourceForm.Text = "Izvorna koda za " + webBrowser1.Url;
			sourceCode.Text = webBrowser1.DocumentText;
			sourceForm.Controls.Add(sourceCode);
			sourceForm.Show(this);
		}

		private void natisniToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.ShowPrintDialog();
		}

		private void predogledTiskanjaToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.ShowPrintPreviewDialog();
		}

		private void lastnostiToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.ShowPropertiesDialog();
		}

		private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
		{
			URL.Text = e.Url.ToString();
		}

		private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
		{
			progbarcek.Value = (int)e.CurrentProgress;
		}

		private void KlonPojdi_Click(object sender, EventArgs e)
		{
			webBrowser1.Navigate(URL.Text);
		}

		private void oProgramuToolStripMenuItem_Click(object sender, EventArgs e)
		{
			about about = new about();
			about.Show();
		}

		private void nazajToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.GoBack();
		}

		private void naprejToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.GoForward();
		}

		private void ustaviToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.Stop();
		}

		private void osvežiToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.Refresh();
		}

		private void domovToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.GoHome();
		}

		private void pojdiToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.Navigate(URL.Text);
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			prikažiToolStripMenuItem.Enabled = false;
			skrijToolStripMenuItem.Enabled = true;
			skrijZaznamkeToolStripMenuItem.Enabled = false;
			listBox1.Visible = false;

			listBox1.MouseDoubleClick += new MouseEventHandler(listBox1_DoubleClick);
			XmlDocument loadDoc = new XmlDocument();
			loadDoc.Load(Application.StartupPath + "\\load.xml");
			Home = loadDoc.SelectSingleNode("/browser/home").Attributes["url"].InnerText;
			webBrowser1.Navigate(Home);

			foreach (XmlNode favNode in loadDoc.SelectNodes("/browser/favorites/item"))
				listBox1.Items.Add(favNode.Attributes["url"].InnerText);
		}

		private void skrijToolStripMenuItem_Click(object sender, EventArgs e)
		{
			toolStrip1.Visible = false;
			prikažiToolStripMenuItem.Enabled = true;
			skrijToolStripMenuItem.Enabled = false;
		}

		private void prikažiToolStripMenuItem_Click(object sender, EventArgs e)
		{
			toolStrip1.Visible = true;
			skrijToolStripMenuItem.Enabled = true;
			prikažiToolStripMenuItem.Enabled = false;
		}

		private void listBox1_DoubleClick(object sender, EventArgs e)
		{
			if (listBox1.SelectedItem != null)
			webBrowser1.Navigate(listBox1.SelectedItem.ToString());
		}

		private void pokažiZaznamkeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			listBox1.Show();
			pokažiZaznamkeToolStripMenuItem.Enabled = false;
			skrijZaznamkeToolStripMenuItem.Enabled = true;
		}

		private void skrijZaznamkeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			listBox1.Hide();
			pokažiZaznamkeToolStripMenuItem.Enabled = true;
			skrijZaznamkeToolStripMenuItem.Enabled = false;
		}

		private void dodajStranToolStripMenuItem_Click(object sender, EventArgs e)
		{
			listBox1.Items.Add(webBrowser1.Url.OriginalString);
		}

		private void žToolStripMenuItem_Click(object sender, EventArgs e)
		{
			listBox1.Items.Remove(listBox1.SelectedItem);
		}

		private void Form1_FormClosing(object sender, FormClosingEventArgs e)
		{
			XmlTextWriter writer = new XmlTextWriter(Application.StartupPath + "\\load.xml", null);

			writer.WriteStartElement("browser");
			writer.WriteStartElement("home");
			writer.WriteAttributeString("url", "www.google.si");
			writer.WriteEndElement();
			writer.WriteStartElement("favorites");
			for (int i = 0; i < listBox1.Items.Count; i++)
			{
				writer.WriteStartElement("item");
				writer.WriteAttributeString("url", listBox1.Items[i].ToString());
				writer.WriteEndElement();
			}
			writer.WriteEndElement();
			writer.WriteEndElement();
			writer.Close();
		}

		private void izhodToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
		{
			tabPage1.Text = e.Url.Authority;
		}

		private void domačaStranToolStripMenuItem_Click(object sender, EventArgs e)
		{
			spremeni spremeni = new spremeni();
			spremeni.Show();
		}

		private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
		{
			statuus.Text = e.Url.ToString();
			this.Text = webBrowser1.DocumentTitle;
			progbarcek.Visible = false;
		}

		private void nastaviToolStripMenuItem_Click(object sender, EventArgs e)
		{
			webBrowser1.Controls.ToString();
		}

Attached File(s)

  • Attached File  load.xml (191bytes)
    Number of downloads: 80


Is This A Good Question/Topic? 0
  • +

Replies To: Webbrowser problem?

#2 JITHU  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: Webbrowser problem?

Posted 08 April 2009 - 05:14 AM

1) I think it's not possible to change the Home page in runtime, the user has to do it manually.
http://msdn.microsof...ser.gohome.aspx


2)For example you can create a public method in Form2 which takes the site URL and add it to the ListBox.
After that create an instance of Form2 class in Form1 class and use it to call the method that you created in Form2 class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1