我试图显示一个已经被带到前面但它在所有其他代码之后执行的picbox [英] I am trying to show a picbox which is already brought to the front but it executes after all other code

查看:63
本文介绍了我试图显示一个已经被带到前面但它在所有其他代码之后执行的picbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按下btnCalculate(按钮计算)时,我试图在其中显示带有.gif的picBox。 picBox已经被带到前面,visible属性被设置为false。我在btnCalculate Sub Procedure之后将visible属性设置为true,然后使用计数器循环尝试让.gif在显示最终计算之前播放约5秒钟。但是,它执行所有代码并且不会显示gif.I我正在使用带有.NET的Visual Studio 2017



其次,我尝试在另一个picBOX中调出具有相同图片的辅助窗体,并禁用MainForm中的picBOX。在MainForm中,我使用frmPicture.ShowDialog()命令,表单出现并覆盖原始表单,但是,如何将第二个表单编码为关闭或隐藏。我尝试使用第二种形式的循环,然后使用Me.Close命令,但这不起作用。然后,我尝试使用Me.Hide命令循环,我收到错误。对不起,伙计们,这是我在Visual Basic中的第一个学期,本书没有详细介绍二级表格。



我尝试了什么:



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:

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

推荐答案

原因是因为显示和计算都在同一个线程中运行。



所以选项是

1.在单独的线程中运行它们参见 https://support.microsoft.com/en-au/help/315577/how-to-create-threads-in-visual-basic-net -or-visual-basic-2005 [ ^ ]



2.快速和脏将Application.doevents()添加到循环中,这可以解决你的问题,但减慢一点
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


我将使用后台工作程序运行计算。
I would run the calculations using a Background Worker.


这篇关于我试图显示一个已经被带到前面但它在所有其他代码之后执行的picbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆