Flickering of a control

  • Thread starter Thread starter Robin Tucker
  • Start date Start date
R

Robin Tucker

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.
 
Will you next time please set your datetime and location to the right one
before you sent a message to this newsgroup.

Thanks

Cor
 
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.
 
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.
 
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top