Results 1 to 15 of 15

Thread: [2005] How do you stop a Marquee from going?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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?

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. Private Sub SetProgressBarStyle(ByVal style As ProgressBarStyle)
    2.     Me.ProgressIndicator.Style = style
    3. End Sub
    Step 2. If your methods have argumentsd or return values then declare a delegate with the same signature:
    vb Code:
    1. Private Delegate Sub SetProgressBarStyleCallback(ByVal style As ProgressBarStyle)
    Now follow steps 3 and 4 and you'll have a solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    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.

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] How do you stop a Marquee from going?

    vb Code:
    1. Private Sub SetProgressBarStyle(ByVal style As ProgressBarStyle)
    2.     If Me.ProgressIndicator.InvokeRequired Then
    3.         'Create and invoke the delegate here.
    4.     Else
    5.         'Access the control member(s) directly here.
    6.     End If
    7. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width