Hi All,
I have a Marquee that starts up and continuously runs and runs. How do I have it start in a stopped state (zeroed out) when the forms loads.
Then when I need to have it start up, how do I get it to start again? Thank you.
Printable View
Hi All,
I have a Marquee that starts up and continuously runs and runs. How do I have it start in a stopped state (zeroed out) when the forms loads.
Then when I need to have it start up, how do I get it to start again? Thank you.
What do you mean by a Marquee? Do you mean a ProgressBar with its Style property set to Marquee? If so then just set its Style to something else and only set the Style to Marquee when you want it to animate.
Hi jmcilhinney,
I meant a Marquee progressbar. I tried what you suggested by changing the style to something else. When I do it, the progressbar disappears.
The code I am using to change the style is (tsProgress is the name of the progressbar):
Code:tsProgress.Style = ProgressBarStyle.Marquee
I figured out why the progressbar is disappearing, the call to turn it into a Marquee is coming from one of my threads.
How do I change the style of a progressbar on the main form from inside a thread?
To access control members from a worker thread you need to use delegation. I've posted several code examples on the forum. Search for invokerequired with my user name and you'll find them.
Hi jmcilhinney,
I was checking out your convo from this page:
http://www.vbforums.com/showthread.p...invokerequired
I am new to threading, and I can almost wrap my head around the concept, but could you supply a quick example of how to control the progressbar from another thread through a delegation?
I am better at understanding if I can see how it works.
Thank for your help.
Read post #20 in that thread and follow the steps outlined in it. You can apply those steps to any member(s) of any control(s). Turning written steps into code is what software developers do. Give it a go and, if it doesn't work, post what you did and we'll see about fixing it. The best way to learn is to do.
I have been trying to get the code to work, but I am having any issues. Can someone throw me a bone? :D
Rather than expect a full working solution, show us what you've done and we can help you modify that to get it to work. I already said that in my last post. Have you followed the steps I outlined in that other thread? If so where did it go wrong? If not then it's not a big surprise that it doesn't work because no-one grasps this concept straight away. I hope that you can at least get the first step: writing a method that accesses the control the way you want.
Below is my code. I need the app to run as long as listbox1 is being populated with data (i can't figure this part out).
ThreadPool = button
ProgressIndicator = progressbar
Listbox1 = listbox
Code:Imports System.Threading
Public Class MainForm
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, MyBase.Load, MyBase.Load, MyBase.Load
ThreadID.Text &= CStr(Thread.CurrentThread.ManagedThreadId)
End Sub
Private Sub theLongRunningTask()
Do While ListBox1.Items.Count < 50
ProgressIndicator.Style = ProgressBarStyle.Marquee
ListBox1.Items.Add("test")
Loop
ProgressIndicator.Style = ProgressBarStyle.Blocks
ProgressIndicator.Value = 0
End Sub
Delegate Sub TaskDelegate()
Private Sub ThreadPool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThreadPool.Click
Dim td As New TaskDelegate(AddressOf theLongRunningTask)
td.BeginInvoke(Nothing, Nothing)
End Sub
End Class
You haven't followed my steps.
Step 1. Write a method to access the member(s) without delegation:Step 2. If your methods have argumentsd or return values then declare a delegate with the same signature:vb Code:
Private Sub SetProgressBarStyle(ByVal style As ProgressBarStyle) Me.ProgressIndicator.Style = style End SubNow follow steps 3 and 4 and you'll have a solution.vb Code:
Private Delegate Sub SetProgressBarStyleCallback(ByVal style As ProgressBarStyle)
This is what I have, but I can't seem to get it to work:
Code:Imports System.Threading
Public Class MainForm
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, MyBase.Load, MyBase.Load, MyBase.Load
ThreadID.Text &= CStr(Thread.CurrentThread.ManagedThreadId)
End Sub
Private Sub theLongRunningTask(ByVal ctl As ProgressBarStyle) '<---what do I do here?
If ctl.InvokeRequired Then
ctl.Invoke(New SetProgressBarStyleCallback(AddressOf SetProgressBarStyle))
Do While ListBox1.Items.Count < 50
ProgressIndicator.Style = ProgressBarStyle.Marquee
ProgressIndicator.Step = 10
ProgressIndicator.Value += 10
ListBox1.Items.Add("test")
' Half-second delay
System.Threading.Thread.Sleep(500)
Loop
End If
End Sub
Delegate Sub TaskDelegate()
Private Sub ThreadPool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThreadPool.Click
Dim td As New TaskDelegate(AddressOf theLongRunningTask)
td.BeginInvoke(Nothing, Nothing)
End Sub
Private Delegate Sub SetProgressBarStyleCallback(ByVal style As ProgressBarStyle)
Private Sub SetProgressBarStyle(ByVal style As ProgressBarStyle)
Me.ProgressIndicator.Style = ProgressBarStyle.Marquee
End Sub
End Class
You simply have NOT followed the steps. What does step 3 say?Where have you done that to your SetProgressBarStyle method?Quote:
Now implement delegation in your methods. To do that you remove the existing body then add the If block that tests whether delegation is required and implements it if it is
I do not understand that part and have no idea how to do that to reach my desired end point.
vb Code:
Private Sub SetProgressBarStyle(ByVal style As ProgressBarStyle) If Me.ProgressIndicator.InvokeRequired Then 'Create and invoke the delegate here. Else 'Access the control member(s) directly here. End If End Sub