By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Flickering of a control

P: n/a
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?

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
There is a progress bar control you know? But otherwise, the reason it
flickers is probably because you are not double buffering it. Create a
bitmap, render to it and then blit the bitmap to the coordinates, rather
than drawing directly onto the e.Graphics context.
"Dragon" <dr****@rol.ru> wrote in message news:d8**********@news.rol.ru...
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?

Nov 21 '05 #2

P: n/a
Will you next time please set your datetime and location to the right one
before you sent a message to this newsgroup.

Thanks

Cor
Nov 21 '05 #3

P: n/a
> blit the bitmap to the coordinates, rather than drawing directly onto the
e.Graphics context.


Do you mean "e.Graphics.DrawImage(myBitmap, 0, 0)"? I've already tried this,
but it does not solve the problem, it only slows redrawing down instead. Is
there another way?

~~~
I am very sorry for invalid date. I've just noticed it was wrong.


Nov 21 '05 #4

P: n/a
You still need to tell it you are doublebuffering so that it wont raise the
PaintBackground event. You need to use SetStyle to make it double buffer,
and there are 3 things. DoubleBuffer, AllPaintingInWMPaint, and UserPaint.
"Dragon" <no@spam.please> wrote in message news:d8**********@news.rol.ru...
blit the bitmap to the coordinates, rather than drawing directly onto the
e.Graphics context.


Do you mean "e.Graphics.DrawImage(myBitmap, 0, 0)"? I've already tried
this,
but it does not solve the problem, it only slows redrawing down instead.
Is
there another way?

~~~
I am very sorry for invalid date. I've just noticed it was wrong.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.