Picturebox being odd

Johnson

Well-known member
Joined
Mar 6, 2009
Messages
158
Programming Experience
Beginner
very simple, I have a picturebox with a animated gif,

ftdcea.jpg


as yuo can see it goes up the bricks, 1,2,3,4 etc as it should

when displayed in my picturebox it goes threw the bricks 1,3,5 then back round next time 2,4,6 and so on

is there some sort of delay?
 
It displays fine here... :confused: The irregularity you describe seems odd. You're not blocking the UI thread by any chance?
 
Rob, it goes 2,4,6, then 1,3,5,7 then 2,4,6 and so on

John how would i know if im blocking it?

even preview in resource select does it :S

might just scrap it for a actual progres bar.

Only reason i used that was because im not sure how to impliment a progres abr with what i want
 
Last edited:
Are you doing extensive work within the UI Thread, f.e. Loops for fetching data etc.?

I've just tried it out to write such an progressbar, and the minimalistic version has about 30 lines...so this is absolutely acceptable. Though, if you implement more options I'd say that it goes up to 250, maybe 350 lines and should be done within a very short time.

Bobby

P.s.: Something to start out with, all you need is to copy this into a user-defined control and add a time (tmr_marquee):
VB.NET:
Imports System.Convert

Public Class ProgressBlocks
    Private prv_blockCount As Integer = 7
    Private prv_blockSpacing As Integer = 3

    Private prv_activeBlock As Integer = 0

    Private prv_marquee As Boolean = False

    Public Sub New()
        InitializeComponent()

        Me.DoubleBuffered = True
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        Me.drawBlocks(e.Graphics)
    End Sub

    Private Sub drawBlocks(ByVal canvas As Graphics)
        Dim blockWidth As Single = ToSingle((Me.Width - Me.Padding.Horizontal - (Me.prv_blockSpacing * (Me.prv_blockCount - 1))) / Me.prv_blockCount)
        Dim x As Single = Me.Padding.Left

        For i As Integer = 0 To Me.prv_blockCount - 1 Step 1
            If i = Me.prv_activeBlock Then
                canvas.FillRectangle(Brushes.Orange, x, Me.Padding.Top, blockWidth, Me.Height - Me.Padding.Vertical)
            Else
                canvas.FillRectangle(Brushes.SlateBlue, x, Me.Padding.Top, blockWidth, Me.Height - Me.Padding.Vertical)
            End If

            x += blockWidth + Me.prv_blockSpacing
        Next
    End Sub

    Private Sub tmr_marquee_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_marquee.Tick
        Me.prv_activeBlock += 1
        If Me.prv_activeBlock >= Me.prv_blockCount Then Me.prv_activeBlock = 0

        Me.Refresh()
    End Sub
End Class
 
Back
Top