New Window event help needed and some other stuff

Can someone please help this code below is mean to opena new window but i don't want it to open my defualt browser i just want it to opne a new window in my browser also i would like my browser to goto the users homepage automatically at startup of the program, and a progress bar that works along with when i click a link it updates in the url box.

My Current code

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace H2F_Browser_Beta

{

public partial class H2FBrowser : Form

{

// Updates the title bar with the current document title.

private void wb_DocumentTitleChanged(object sender, EventArgs e)

{

this.Text = wb.DocumentTitle;

}

// Updates the status bar with the current browser status text.

private void wb_StatusTextChanged(object sender, EventArgs e)

{

//toolStripStatusLabel1.Text = wb.StatusText;

}

private void wb_NewWindow(Object sender, CancelEventArgs e)

{

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();

messageBoxCS.AppendFormat("{0} = {0}", "Cancel", e.Cancel);

messageBoxCS.AppendLine();

MessageBox.Show(messageBoxCS.ToString(), "NewWindow Event");

}

// Navigates webBrowser1 to the next page in history.

private void cmdForward_Click(object sender, EventArgs e)

{

wb.GoForward();

}

// Disables the Forward button at the end of navigation history.

private void wb_CanGoForwardChanged(object sender, EventArgs e)

{

cmdForward.Enabled = wb.CanGoForward;

}

private void cmdBack_Click(object sender, EventArgs e)

{

wb.GoBack();

}

// Disables the Back button at the beginning of the navigation history.

private void wb_CanGoBackChanged(object sender, EventArgs e)

{

cmdBack.Enabled = wb.CanGoBack;

}

// Navigates to the URL in the address box when

// the ENTER key is pressed while the ToolStripTextBox has focus.

private void txtURL_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Enter)

{

Navigate(txtURL.Text);

}

}

// Navigates to the URL in the address box when

// the Go button is clicked.

private void cmdGo_Click(object sender, EventArgs e)

{

Navigate(txtURL.Text);

}

// Navigates to the given URL if it is valid.

private void Navigate(String address)

{

if (String.IsNullOrEmpty(address)) return;

if (address.Equals("about:blank")) return;

if (!address.StartsWith("http://") &&

!address.StartsWith("https://"))

{

address = "http://" + address;

}

try

{

wb.Navigate(new Uri(address));

txtURL.Text = address;

}

catch (System.UriFormatException)

{

return;

}

}

private void CreateMyStatusBar()

{

// Create a StatusBar control.

StatusBar statusBar1 = new StatusBar();

// Create two StatusBarPanel objects to display in the StatusBar.

StatusBarPanel panel1 = new StatusBarPanel();

StatusBarPanel panel2 = new StatusBarPanel();

// Display the first panel with a sunken border style.

panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken;

// Initialize the text of the panel.

panel1.Text = "Ready...";

// Set the AutoSize property to use all remaining space on the StatusBar.

panel1.AutoSize = StatusBarPanelAutoSize.Spring;

// Display the second panel with a raised border style.

panel2.BorderStyle = StatusBarPanelBorderStyle.Raised;

// Create ToolTip text that displays time the application was

//started.

panel2.ToolTipText = "Started: " + System.DateTime.Now.ToShortTimeString();

// Set the text of the panel to the current date.

panel2.Text = System.DateTime.Today.ToLongDateString();

// Set the AutoSize property to size the panel to the size of the contents.

panel2.AutoSize = StatusBarPanelAutoSize.Contents;

// Display panels in the StatusBar control.

statusBar1.ShowPanels = true;

// Add both panels to the StatusBarPanelCollection of the StatusBar.

statusBar1.Panels.Add(panel1);

statusBar1.Panels.Add(panel2);

// Add the StatusBar to the form.

this.Controls.Add(statusBar1);

}

// Initialize a single-panel status bar. This is done

// by setting the Text property and setting ShowPanels to False.

private void InitializeSimpleStatusBar()

{

// Declare the StatusBar control

StatusBar simpleStatusBar = new StatusBar();

// Set the ShowPanels property to False.

simpleStatusBar.ShowPanels = false;

// Set the text.

simpleStatusBar.Text = "This is a single-panel status bar";

// Set the width and anchor the StatusBar

simpleStatusBar.Width = 200;

simpleStatusBar.Anchor = AnchorStyles.Top;

// Add the StatusBar to the form.

this.Controls.Add(simpleStatusBar);

}

// Updates the URL in TextBoxAddress upon navigation.

private void wb_Navigated(object sender,

WebBrowserNavigatedEventArgs e)

{

txtURL.Text = wb.Url.ToString();

}

public H2FBrowser()

{

InitializeComponent();

}

private void cmdGo_Click_1(object sender, EventArgs e)

{

Navigate(txtURL.Text);

}

private void cmdBack_Click_1(object sender, EventArgs e)

{

wb.GoBack();

}

// Navigates webBrowser1 to the home page of the current user.

private void cmdHome_Click(object sender, EventArgs e)

{

wb.GoHome();

}

private void cmdForward_Click_1(object sender, EventArgs e)

{

wb.GoForward();

}

private void ToolStripStatusLabel1_Click(object sender, EventArgs e)

{

//ToolStripStatusLabel1.Text = wb.StatusText;

}

internal System.Windows.Forms.StatusBar statusBar1;

private void InitializeStatusBarPanels()

{

// Create a StatusBar control.

statusBar1 = new StatusBar();

// Dock the status bar at the top of the form.

statusBar1.Dock = DockStyle.Top;

// Set the SizingGrip property to false so the user cannot

// resize the status bar.

statusBar1.SizingGrip = false;

// Associate the event-handling method with the

// PanelClick event.

statusBar1.PanelClick += new StatusBarPanelClickEventHandler(statusBar1_PanelClick);

// Create two StatusBarPanel objects to display in statusBar1.

StatusBarPanel panel1 = new StatusBarPanel();

StatusBarPanel panel2 = new StatusBarPanel();

// Set the width of panel2 explicitly and set

// panel1 to fill in the remaining space.

panel2.Width = 80;

panel1.AutoSize = StatusBarPanelAutoSize.Spring;

// Set the text alignment within each panel.

panel1.Alignment = HorizontalAlignment.Left;

panel2.Alignment = HorizontalAlignment.Right;

// Display the first panel without a border and the second

// with a raised border.

panel1.BorderStyle = StatusBarPanelBorderStyle.None;

panel2.BorderStyle = StatusBarPanelBorderStyle.Raised;

// Set the text of the panels. The panel1 object is reserved

// for line numbers, while panel2 is set to the current time.

panel1.Text = "Reserved for important information.";

panel2.Text = System.DateTime.Now.ToShortTimeString();

// Set a tooltip for panel2

panel2.ToolTipText = "Click time to display seconds";

// Display panels in statusBar1 and add them to the

// status bar's StatusBarPanelCollection.

statusBar1.ShowPanels = true;

statusBar1.Panels.Add(panel1);

statusBar1.Panels.Add(panel2);

// Add the StatusBar to the form.

this.Controls.Add(statusBar1);

}

// Reloads the current page.

private void cmdRefresh_Click(object sender, EventArgs e)

{

// Skip refresh if about:blank is loaded to avoid removing

// content specified by the DocumentText property.

if (!wb.Url.Equals("about:blank"))

{

wb.Refresh();

}

}

// Halts the current navigation and any sounds or animations on

// the page.

private void cmdStop_Click(object sender, EventArgs e)

{

wb.Stop();

}

// If the user clicks the status bar, check the text of the

// StatusBarPanel. If the text equals a short time string,

// change it to long time display.

private void statusBar1_PanelClick(object sender, StatusBarPanelClickEventArgs e)

{

if (e.StatusBarPanel.Text == System.DateTime.Now.ToShortTimeString())

{

e.StatusBarPanel.Text =

System.DateTime.Now.ToLongTimeString();

}

}

private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

}

private void cmdHome_Click_1(object sender, EventArgs e)

{

wb.GoHome();

}

private void cmdRefresh_Click_1(object sender, EventArgs e)

{

if (!wb.Url.Equals("about:blank"))

{

wb.Refresh();

}

}

private void cmdStop_Click_1(object sender, EventArgs e)

{

wb.Stop();

}

}

}

Thanks




Answer this question

New Window event help needed and some other stuff

  • K Sumeet

    Ok well the two main things what i would like to be able to get working correctly would be to open new windows in my program and not the default internet program, and to have a progress bar to work is that ok to ask or is to much sorry about before.

  • vaioks

    That's a little too much to ask on a forum like this. You'll get a better response if you post a single problem per topic and explain what you've already done about that specific problem (i.e., avoid posting code that is irrelevant to the immediate problem).

  • drewdb

    How and when do you want the new windows to open

    How:
    1) In a new tab or MDI contained form in your browser window
    2) In a new browser window that is still running in the same process
    3) In a new process

    When:
    1) When the user specifically asks for it (e.g., File->New Window or Ctrl+Enter in the address bar).
    2) Whenever they click on a link in your browser that would normally open a new window (not sure, but this may be difficult)
    3) When accessing any website systemwide (e.g., Start->Run and entering "http://www.google.com").

    Each way will require somewhat different code. And just so you know, I've never used the webbrowser control in .NET, although I did use a .ocx one years ago in VB6.

  • JezPop

    how:


    2) In a new browser window that is still running in the same process

    When:

    1: File New Window

    2: say if in a html code its tells the browser to open a new browser window.

    thank



  • New Window event help needed and some other stuff