ProgressBar within a custom control is not updated correctly VB.NET

0

I am creating a custom control that what is intended is to make a progress bar, so that you can define a number of processes, and that each of these processes is assigned a different proportion of the process bar, in addition that each process could eventually not be filled in the same number of steps, and I decided to leave this in a UserControl that contained all this logic. This UserControl has 2 label (one that says "Progress Status" and one that shows progress as a percentage) and a progressbar. I also have another class (General), in which I have 2 functions load_bar and download_bar, which create and destroy a usercontrol object defined before and add or remove it from the collection of controls in the form (which for both functions is received as a parameter of the function.

Finally I have a simple form with a button that all it does is execute a code (as a test of the UserControl)

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim barra As ProgressShow
        barra = general.cargar_barra(Me)
        barra.inicializar(5)
        For i = 1 To 5
            Threading.Thread.Sleep(1000 * 2)
            barra.continua_proceso()
            Threading.Thread.Sleep(1000 * 0.5)
        Next
        general.descargar_barra(Me)
    End Sub

Everything seems to work fine, however, the label with the progress percentage is updated correctly with the percentage of each cycle turn, however the advancebar of the progressbar remains behind one cycle turn (label 20% progressbar : 0, label 40% progressbar 20 and so ...)

I think the problem can be in the function draw_status, where I calculate the value that the bar must have according to its progress, I tried to leave with these lines but even so the bar always remains one turn back in the cycle

    barra1.Value = CInt(valor_mostrar)
    barra1.Refresh()
    porcent.Text = Format(valor_mostrar / 100, "##0.00%")
    Windows.Forms.Application.DoEvents()
    Thread.Sleep(50)

I think that leaving all the code in my post can be annoying, so I leave you a Visual Studio 2010 project with the project working (remove the code that was not necessary for the example) Sources of the Example

If someone could tell me how to solve the problem, I would greatly appreciate it, in one of those the solution would be a totally different method, so I accept other ideas, greetings.

    
asked by Ariel Akuze Quispe 26.01.2017 в 21:43
source

0 answers