|
-
Apr 18th, 2007, 11:25 PM
#1
Thread Starter
Addicted Member
[2005] How do you stop a Marquee from going?
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.
-
Apr 19th, 2007, 12:10 AM
#2
Re: [2005] How do you stop a Marquee from going?
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.
-
Apr 19th, 2007, 06:04 AM
#3
Thread Starter
Addicted Member
Re: [2005] How do you stop a Marquee from going?
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
Last edited by Giraffe Frenzy; Apr 19th, 2007 at 06:08 AM.
-
Apr 19th, 2007, 06:38 AM
#4
Thread Starter
Addicted Member
Re: [2005] How do you stop a Marquee from going?
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?
-
Apr 19th, 2007, 08:40 AM
#5
Re: [2005] How do you stop a Marquee from going?
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.
-
Apr 19th, 2007, 10:18 AM
#6
Thread Starter
Addicted Member
Re: [2005] How do you stop a Marquee from going?
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.
-
Apr 19th, 2007, 08:01 PM
#7
Re: [2005] How do you stop a Marquee from going?
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.
-
Apr 19th, 2007, 09:59 PM
#8
Thread Starter
Addicted Member
Re: [2005] How do you stop a Marquee from going?
I have been trying to get the code to work, but I am having any issues. Can someone throw me a bone?
-
Apr 19th, 2007, 10:21 PM
#9
Re: [2005] How do you stop a Marquee from going?
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.
-
Apr 20th, 2007, 06:14 AM
#10
Thread Starter
Addicted Member
Re: [2005] How do you stop a Marquee from going?
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
Last edited by Giraffe Frenzy; Apr 20th, 2007 at 06:20 AM.
-
Apr 20th, 2007, 06:22 AM
#11
Re: [2005] How do you stop a Marquee from going?
You haven't followed my steps.
Step 1. Write a method to access the member(s) without delegation:
vb Code:
Private Sub SetProgressBarStyle(ByVal style As ProgressBarStyle)
Me.ProgressIndicator.Style = style
End Sub
Step 2. If your methods have argumentsd or return values then declare a delegate with the same signature:
vb Code:
Private Delegate Sub SetProgressBarStyleCallback(ByVal style As ProgressBarStyle)
Now follow steps 3 and 4 and you'll have a solution.
-
Apr 20th, 2007, 06:33 AM
#12
Thread Starter
Addicted Member
Re: [2005] How do you stop a Marquee from going?
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
-
Apr 20th, 2007, 06:45 AM
#13
Re: [2005] How do you stop a Marquee from going?
You simply have NOT followed the steps. What does step 3 say?
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
Where have you done that to your SetProgressBarStyle method?
-
Apr 20th, 2007, 06:49 AM
#14
Thread Starter
Addicted Member
Re: [2005] How do you stop a Marquee from going?
I do not understand that part and have no idea how to do that to reach my desired end point.
-
Apr 20th, 2007, 06:50 AM
#15
Re: [2005] How do you stop a Marquee from going?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|