7 Replies - 1783 Views - Last Post: 01 December 2008 - 02:33 PM Rate Topic: -----

#1 KJc  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-November 08

Progress bar

Post icon  Posted 30 November 2008 - 09:39 AM

Hi,
Can anyone tell me why my progress bar is not working?... it was working fine till I decided to add tabs to my browser.

This is the code


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		   'Progress Bar
		Me.lblApplicationStatus.Text = "Ready"

	End Sub


Private Sub Browser(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)

		   Me.lblApplicationStatus.Text = "Navigating to:" + e.Url.Host.ToString()

	 End Sub

  Private Sub Browser_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs)

			 If e.CurrentProgress < e.MaximumProgress Then
		   
			If pbStatus.Value >= pbStatus.Maximum Then
			 pbStatus.Value = pbStatus.Minimum

			Else
			   
			 pbStatus.PerformStep()

			End If

			 Else

			 pbStatus.Value = pbStatus.Minimum

		End If

	End Sub

 Private Sub Browser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
	   
		If My.Application.Info.Title <> "" Then
		 Me.Text = My.Application.Info.Title + " - " + e.Url.Host.ToString()

		Else

		  Me.Text = System.IO.Path.GetFileNameWithoutExtension( _
		  My.Application.Info.AssemblyName) + " - " + e.Url.Host.ToString()

		End If

		  Me.lblApplicationStatus.Text = "Ready"

	End Sub



Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Progress bar

#2 KJc  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-November 08

Re: Progress bar

Posted 30 November 2008 - 11:10 AM

Sorry..I forgot to say that am using VB.Net 2005 Express Edition
Was This Post Helpful? 0
  • +
  • -

#3 VB Crash  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 130
  • Joined: 28-November 08

Re: Progress bar

Posted 30 November 2008 - 01:11 PM

Use this code

progressbar1.value=progressbar1.value + 1



Font forget to set the Maximum Properties.

Vace
Was This Post Helpful? 0
  • +
  • -

#4 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Progress bar

Posted 30 November 2008 - 01:32 PM

I'm not seeing any Handles clauses on any of those sub's in your code. That is your problem. The only sub i'm seeing a handles clause on is your Form's load sub, but i see none on any of the subs to handle the events for the browser. For example, the signature of your progress changed sub looks like

Private Sub Browser_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs)

However, it must have a Handles clause to tell it to fire on the Browser_ProgressChanged event:

Private Sub Browser_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles Browser.ProgressChanged

Also, if you have more than one web browser, you can set the sub to fire on multiple events by separating them with a comma

Private Sub Browser_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles Browser.ProgressChanged, Browser2.ProgressChanged, Browser3.ProgressChanged

I am 99% sure that is your problem.
Was This Post Helpful? 0
  • +
  • -

#5 KJc  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-November 08

Re: Progress bar

Posted 30 November 2008 - 04:13 PM

[quote name='jacobjordan' date='30 Nov, 2008 - 12:32 PM' post='477150']
I'm not seeing any Handles clauses on any of those sub's in your code. That is your problem. The only sub i'm seeing a handles clause on is your Form's load sub, but i see none on any of the subs to handle the events for the browser. For example, the signature of your progress changed sub looks like

You are right... I added this to Form1_load
AddHandler browser.ProgressChanged, AddressOf browse_done_ProgressChanged


and it worked! :-) but.. when I open another tab on my browser then it does not work on that second... third..etc..etc.. tab.. only on the first tab.

Also for some reason I get an error if I add the handle : Handles Browser.ProgressChanged

to the:
Private Sub Browser_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles Browser.ProgressChanged

this is the error:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

#6 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Progress bar

Posted 30 November 2008 - 04:37 PM

I'm gonna need some more information on how your tab system works to fix this. I am assuming you are creating a new webbrowser object every new tab. If that is what you are doing, simply use AddHandler to add a handler for that new web browser. Oh, and by the way, if you don't need to use the handles clauses if your going to use AddHandler.
Was This Post Helpful? 0
  • +
  • -

#7 KJc  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-November 08

Re: Progress bar

Posted 01 December 2008 - 12:49 AM

View Postjacobjordan, on 30 Nov, 2008 - 03:37 PM, said:

I'm gonna need some more information on how your tab system works to fix this. I am assuming you are creating a new webbrowser object every new tab. If that is what you are doing, simply use AddHandler to add a handler for that new web browser. Oh, and by the way, if you don't need to use the handles clauses if your going to use AddHandler.



Here the tabs code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load	 
 
		Dim browse As New WebBrowser
		browse.Name = "B1"
		browse.Dock = DockStyle.Fill
		AddHandler browse.DocumentCompleted, AddressOf browse_done
		
		AddHandler browse.ProgressChanged, AddressOf browse_done_ProgressChanged
	   
		TabControl1.TabPages.Add(i, "page" & i + 1)
		TabControl1.SelectTab(i)
		TabControl1.SelectedTab.Controls.Add(browse)
		i = i + 1

		 Me.lblApplicationStatus.Text = "Ready"

End Sub

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
   
End Sub

Private Sub browse_done(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
		
		TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0),   WebBrowser).DocumentTitle

		Me.lblApplicationStatus.Text = "Navigating to:" + e.Url.Host.ToString()

	End Sub

Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
		' to Add tabs
		Dim browse As New WebBrowser
		browse.Name = "B1"
		browse.Dock = DockStyle.Fill
		AddHandler browse.DocumentCompleted, AddressOf browse_done
		TabControl1.TabPages.Add(i, "page" & i + 1)
		TabControl1.SelectTab(i)
		TabControl1.SelectedTab.Controls.Add(browse)
		i = i + 1
	End Sub

 Private Sub ToolStripProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbStatus.Click

	End Sub

	Private Sub TabControl1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

	End Sub

 Private Sub browse_done_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs)

		If e.CurrentProgress < e.MaximumProgress Then
		 If pbStatus.Value >= pbStatus.Maximum Then
				pbStatus.Value = pbStatus.Minimum
			Else
				pbStatus.PerformStep()
			End If
			Else
				pbStatus.Value = pbStatus.Minimum
		   End If


	End Sub

	   Private Sub browse_done_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)

			   If My.Application.Info.Title <> "" Then
			Me.Text = My.Application.Info.Title + " - " + e.Url.Host.ToString()
		Else
			Me.Text = System.IO.Path.GetFileNameWithoutExtension( _
			My.Application.Info.AssemblyName) + " - " + e.Url.Host.ToString()

		End If

			   Me.lblApplicationStatus.Text = "Ready"

	End Sub



Thanks once again.
Was This Post Helpful? 0
  • +
  • -

#8 KJc  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-November 08

Re: Progress bar

Posted 01 December 2008 - 02:33 PM

[quote name='KJc' date='30 Nov, 2008 - 11:49 PM' post='477531']

View Postjacobjordan, on 30 Nov, 2008 - 03:37 PM, said:

I'm gonna need some more information on how your tab system works to fix this. I am assuming you are creating a new webbrowser object every new tab. If that is what you are doing, simply use AddHandler to add a handler for that new web browser. Oh, and by the way, if you don't need to use the handles clauses if your going to use AddHandler.



I think that I got it!! :-)

I just added an AddHandler to the Private Sub to add new tabs and so far it seemed that it did the trick.

Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1