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? 4 1416
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?
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.
"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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BestNews |
last post by:
Hi,
I used an ActiveX control in C# client Application . I have
created 'n' number of ActiveX controls on the UserControl. After user
interaction some of the activeX control have to be refreshed...
|
by: Joaquin Grech |
last post by:
Hi
I did alot of research on this on the web and msdn and I couldn't find
anything.
I have a listview showing as a grid (table looking, with rows and columns
and no images at all, only text)....
|
by: Jack Smash |
last post by:
Hi,
I'm using a UserControl object for all the graphics handling in my
application. However, if I select an image and move it around, I get
flickering. So in order to get rid of the flickering,...
|
by: John Lee |
last post by:
Hi,
I have a windows application that uses the listview to display about 50
items in detailed view - 4 columns. The first column is static and other
columns will be updated in 100-1000ms - it...
|
by: John Lee |
last post by:
Thanks Jay for your response.
I tried your code and it still flickering a lot. To demonstrate it, you can
grab a listview, create 3 columns - name, value, timestamp, in form_load
event to add 50...
|
by: Brian Henry |
last post by:
I created a smooth progress bar with this code.. but if you update the
values in a row quickly of it and watch it on screen it flickers... how
would i change this to reduce the flickering?...
|
by: Jim Hubbard |
last post by:
Has anyone seen a fix for the flickering effect you get when resizing a
Webbrowser control?
It's really irritating and doesn't make for a professional-looking
application.
|
by: n00b |
last post by:
I have some forms with maybe around 30 controls on each and anytime I load
these forms different parts of it start flickering though not all of them at
once and not the same ones everytime. the...
|
by: Mark Thompson |
last post by:
I have a problem with my Visual Basic .NET 2003 application which I
have so far been unable to resolve.
I am trying to get an OpenGL control that I have created working
properly as a control on...
|
by: kulabhishek |
last post by:
Hello all.
I have developed one user control "Grid" in C# and I am using it in another user control inside one panel.
The AutoScroll property for the panel is enabled.
When the height or...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |