Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to show a picBox with a .gif in it when I press the btnCalculate (button Calculate). The picBox is already brought to the front and the visible property is set to false. I set the visible property to true after the btnCalculate Sub Procedure then use a counter loop to try and let the .gif play for about 5 seconds before it shows the final calculations. However, it executes all code and doesn't ever show the gif.I am using Visual Studio 2017 with .NET

Secondarily, I have tried bringing up a secondary windows form with the same picture in another picBOX and disabled the picBOX from the MainForm. In the MainForm, I use the frmPicture.ShowDialog() command and the form comes up and covers the original form, however, how would I code the second form to either close or hide. I attempted to use use a loop in the second form and then the Me.Close command and that did not work. I then attempted a loop with the Me.Hide command and I get an error. Sorry guys, this is my first semester in Visual Basic and the book doesn't go into detail about secondary forms.

What I have tried:

VB
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        picBox.Visible = True
        picBox.BringToFront()

        'Sound Effect on button click
        My.Computer.Audio.Play(My.Resources._41089869_coffee_maker_brewing_coffee_02, AudioPlayMode.Background)

        Dim intCount As Integer = 1
        For intCount = 1 To 1000000000

        Next


        'This procedure calculates the total of an order
        Dim decSubtotal As Decimal      'Holds the order subtotal
        Dim decTax As Decimal           'Holds the sales tax
        Dim decTotal As Decimal         'Holds the order total

        decSubtotal = CalcBagelCost() + CalcToppingCost() + CalcCoffeeCost()
        decTax = CalcTax(decSubtotal)
        decTotal = decSubtotal + decTax

        lblSubtotal.Text = decSubtotal.ToString("c")
        lblTax.Text = decTax.ToString("c")
        lblTotal.Text = decTotal.ToString("c")


        picBox.Visible = False


    End Sub
Posted
Updated 29-Aug-18 4:43am
v3

The reason is because the display and the calculations are all running in the same thread.

So the options are
1. Run them in separate threads See https://support.microsoft.com/en-au/help/315577/how-to-create-threads-in-visual-basic-net-or-visual-basic-2005[^]
or
2. As a quick and dirty add Application.doevents() to the loop, which may solve your problem, but slow it down a bit
 
Share this answer
 
I would run the calculations using a Background Worker.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900