Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Sorry if this is a bit open ended but can anyone show me how to code a progress bar? Basically i have my .Net program ship a load of data into some tables in Word but it takes a few minutes and so i want to keep the user informed of its progress. How do i put in a bar to show the progress of the Word population?

I have looked at threading and just got totally lost any help would be appreciated.

  • *Experts*
Posted

Drag a progress bar onto your form from the Toolbox, then you can set the value of it using the .Value property. You will have to figure out for yourself what position the progress bar should be on, for example if you have a For Next loop that runs 100 you could increase the value by 1. Do you have some more specifiec questions than how to program a progress bar :) ?

:)

Posted

Sorry, I can't help but hijack these progress bar threads, but I'm still looking for a way to make my progress bar look 'smooth', like I could in VB6 by setting the scrolling property.

 

I upgrade some VB6 code with a button that switched between the two modes and this was converted:

 

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
	If ProgressBar1.Scrolling = MSComctlLib.ScrollingConstants.ccScrollingSmooth Then
		ProgressBar1.Scrolling = MSComctlLib.ScrollingConstants.ccScrollingStandard
	Else
		ProgressBar1.Scrolling = MSComctlLib.ScrollingConstants.ccScrollingSmooth
	End If
End Sub

 

Is this using the VB6 component library???

  • *Gurus*
Posted
No, that's using the common controls ActiveX control, which you should never do. You're right that the Windows Forms progressbar class lacks a way to achieve this effect. If you really want it, I suggest you derive your own class from ProgressBar, override the CreateParams property and add the PBS_SMOOTH constant to the window styles.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Just about stumbled that far myself, thanks (though, I concede, the ambiguity was in the question!)

 

What I was keen to know was: given that I want to use the progress bar for the obvious purpose (i.e updating the user on progress), is there a straightforward way to thread (a) the activity in question, and (b) the status update in the progress bar, so that the user gets to keep tabs on what's going on? I guess, on reflection, this is more of a "Newbie Does Threads" topic than a ProgressBar post!

 

Having made a bit of progress (!) myself, I've cooked up the following example, where (on Button1.click) TextBox1 begins a cycle from 1 to 10,000, while ProgressBar1 does what it does best, and relates progress:

 

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim FredTheThread As New System.Threading.Thread(AddressOf txtbox)
       Dim TedTheThread As New System.Threading.Thread(AddressOf progbox)
       FredTheThread.Start()
       TedTheThread.Start()
   End Sub
   Sub progbox()
       With ProgressBar1
           .Minimum = 0
           .Maximum = 100
           .Step = 1
           Do
               .Value = Val(TextBox1.Text) / 100
               .PerformStep()
               Threading.Thread.Sleep(500)
           Loop Until .Value = .Maximum
       End With
   End Sub
   Sub txtbox()
       Dim fornextloop
       For fornextloop = 1 To 10000
           TextBox1.Text = fornextloop
           TextBox1.Refresh()
       Next fornextloop
   End Sub

 

Okay, so: who wants to rip this to shreds?

 

(Oh, and, having now got this far, entirely see where you're coming from, samsmithnz.)

Posted
No, that's using the common controls ActiveX control, which you should never do. You're right that the Windows Forms progressbar class lacks a way to achieve this effect. If you really want it, I suggest you derive your own class from ProgressBar, override the CreateParams property and add the PBS_SMOOTH constant to the window styles.

 

Hmmm, thats what I was afraid of, I don't know why they removed that option, the 'blocky' progress bar sucks monkey balls (and doesn't look all that accurate).

 

thanks, and sorry I temporarly hijacked the thread. :)

  • 1 month later...
  • *Experts*
Posted

No such thing as stupid questions...

You should almost never use ActiveX unless there's no .NET alternative. I won't go into all the reasons, but they're a bit slower (going through COM), not managed code, and harder to install on client machines (must be registered).

 

If you have a .NET alternative it's usually best to use that.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...