Hello!
I'm writing user control, the custom progress bar. It should show current
position, when application is playing an MP3 file. The problem is that
sometimes, when it redraws itself, it flickers undesirably, spoiling all the
impression. I can not find any regularity in its behaviour. It moves
smoothly, then suddenly flickers, and continues moving.
Here is the fragment of my code:
Private Sub PlayingSlideBar_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim Middle As Integer = GetMiddle(CurrentTime.Ticks) 'GetMiddle()
returns current position of the crawler
Dim MiddleRectangle As New Rectangle(Middle - 5, 0, 10, Height)
e.Graphics.FillRectangle(New SolidBrush(LColor), New Rectangle(0, 0,
Middle - 5, Height))
e.Graphics.FillRectangle(New SolidBrush(RColor), New Rectangle(Middle +
5, 0, Width, Height)) 'LColor and RColor are properties of a control
e.Graphics.FillRectangle(New
Drawing2D.LinearGradientBrush(MiddleRectangle, LColor, RColor,
Drawing2D.LinearGradientMode.Horizontal), MiddleRectangle)
If Border > 0 Then e.Graphics.DrawRectangle(New Pen(Color.Black,
(Border - 1) * 2 + 1), New Rectangle(0, 0, Width - 1, Height - 1))
e.Dispose()
End Sub
Public Property TimeNow() As TimeSpan 'it represents current value
Get
Return CurrentTime 'CurrentTime is internal variable
End Get
Set(ByVal Value As TimeSpan)
Dim OldValueTicks As Long = CurrentTime.Ticks
If Value.Ticks < TrackLength.Ticks Then CurrentTime = Value Else CurrentTime
= TrackLength
If GetMiddle(Value.Ticks) <> GetMiddle(OldValueTicks) Then Refresh()
End Set
End Property
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Maybe, I'm doing something wrong?