I have a form with only 1 object on it , a progress bar.

when the form loads it runs the progress bar, which is working fine.

when the progress bar hits the max vaule i want the form to close but
no matter where i put the me.close the form always stays open.

can anyone help?

`
Public Class FrmPleaseWait

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



    Dim x As Integer
    Dim y As Integer
    x = Screen.PrimaryScreen.WorkingArea.Width - 525
    y = Screen.PrimaryScreen.WorkingArea.Height - 190
    Me.Location = New Point(x, y)


    CheckForIllegalCrossThreadCalls = False





    With ProgressBar1
        .Style = ProgressBarStyle.Blocks
        .Step = 1
        .Minimum = _MinProgressbarValue
        .Maximum = _MaxProgressbarValue
        .Value = _ProgressbarValue
    End With


    With ProgressBar1
        .Style = ProgressBarStyle.Blocks
        .Step = 1
        .Minimum = _MinProgressbarValue
        .Maximum = _MaxProgressbarValue
        .Value = _ProgressbarValue
    End With
    'if you repress the button now, it won't restart now
    Do
        'ALL events in your form will ahve to wait until this loop is completed!
        Threading.Thread.Sleep(100)
        ProgressBar1.PerformStep() 'can't use this if ProgressBar1.Style = ProgressBarStyle.Marquee

    Loop Until ProgressBar1.Value >= ProgressBar1.Maximum

    Me.Close()

End Sub

End Class`

Try using a timer instead and on a timer put something like this:

If ProgressBar1.Maximum = 100 Then
close()
End If

Then you will have to add the Timer1.Start() on your Form_Load

Thanks Mr M

just a bit more info the form is a MdiChild form open within the parent
I have already tried the code you sugested however the form is still open
within my parent. (See attachment)

Public Class FrmPleaseWait

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



        Dim x As Integer
        Dim y As Integer
        x = Screen.PrimaryScreen.WorkingArea.Width - 525
        y = Screen.PrimaryScreen.WorkingArea.Height - 190
        Me.Location = New Point(x, y)


        CheckForIllegalCrossThreadCalls = False





        With ProgressBar1
            .Style = ProgressBarStyle.Blocks
            .Step = 1
            .Minimum = _MinProgressbarValue
            .Maximum = _MaxProgressbarValue
            .Value = _ProgressbarValue
        End With


        With ProgressBar1
            .Style = ProgressBarStyle.Blocks
            .Step = 1
            .Minimum = _MinProgressbarValue
            .Maximum = _MaxProgressbarValue
            .Value = _ProgressbarValue
        End With
        'if you repress the button now, it won't restart now
        Do
            'ALL events in your form will ahve to wait until this loop is completed!
            Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep() 'can't use this if ProgressBar1.Style = ProgressBarStyle.Marquee

        Loop Until ProgressBar1.Value >= ProgressBar1.Maximum



        If ProgressBar1.Maximum = 100 Then
            Close()
        End If
    End Sub



End Class

Ok. I have just looked through the code and half of the attachment because of my internet. But I have some Questions.

Why you have

 With ProgressBar1
.Style = ProgressBarStyle.Blocks
.Step = 1
.Minimum = _MinProgressbarValue
.Maximum = _MaxProgressbarValue
.Value = _ProgressbarValue
End With

Twice and also why > because if the progress value is more then 100 the error is thrown?

Also if you say you are using a MDI then try something like this:

For Each xChild As Form In Me.MdiParent.MdiChildren
xChild.Close()
Next xChild

To see if all active child forms won't close.

Mr M

Resolved thank you for pointing out the obvious, I have been looking at the code that long
that I hadn't spotted it. although that wasn't was resolved it.

I added the performstep process into a thread

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



        'Dim x As Integer
        'Dim y As Integer
        'x = Screen.PrimaryScreen.WorkingArea.Width - 425
        'y = Screen.PrimaryScreen.WorkingArea.Height - 190
        'Me.Location = New Point(x, y)


        CheckForIllegalCrossThreadCalls = False




        With ProgressBar1
            .Style = ProgressBarStyle.Blocks
            .Step = 1
            .Minimum = _MinProgressbarValue
            .Maximum = _MaxProgressbarValue
            .Value = _ProgressbarValue
        End With

        Thread_1 = New Thread(AddressOf ProgressBar_Step)
        Thread_1.Start()

    End Sub

    Private Sub ProgressBar_Step()
        Do
            'ALL events in your form will ahve to wait until this loop is completed!
            Threading.Thread.Sleep(100)
            ProgressBar1.PerformStep() 'can't use this if ProgressBar1.Style = ProgressBarStyle.Marquee

        Loop Until ProgressBar1.Value = ProgressBar1.Maximum

        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Me.Close()
        End If

    End Sub

Glad you figured the way out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.