Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I'm making a custom progressbar where there is a gray background (2) and the progress rectangle (1) is blue. To show progress being made, the progress rectangle increases in width (see diagram).

VB
 _____________________
|            |        |
|     1      |--> 2   |
|____________|________|

The problem is that even with the following code, the progress rectangle flickers:

VB
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)


The progress rectangle's width is coded to increase by 1 up to 400 on a timer with the interval 100ms.

Please help. I can't find any other answers and I don't want to have to create a flash animation.

-Rixterz
Posted

That could be useful:
SO: Why do my WinForms controls flicker and resize slowly?[^]

Could you show us the method overriding OnPaint()?
 
Share this answer
 
Comments
[no name] 10-Jun-14 16:36pm    
I don't have a method overriding OnPaint(). I'm just doing RectangleShape1.Width +=1.
Sergey Alexandrovich Kryukov 10-Jun-14 19:35pm    
Then SuspendLayout/ResumeLayout can help. Actually, rendering in OnPaint or a handler of Paint could be a better alternative.
—SA
[no name] 11-Jun-14 4:43am    
Is this what you meant:

Private Sub RectangleShapes_Paint(sender As Object, e As PaintEventArgs) Handles RectangleShape1.Paint, RectangleShape2.Paint
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
End Sub

This still produces a flicker. My computer is 5 years old, but surely, even with the horrible graphics capability, you can still resize a rectangleshape without flicker!
phil.o 11-Jun-14 5:58am    
No, the SetStyle method typically is used from the Program.Main() method.
What goes in the OnPaint() method is the code responsible for drawing the control. Please see the examples in the provided link.
[no name] 11-Jun-14 6:32am    
I'm not making a custom control; i have 2 rectangleshapes. I said "custom" because i'm not using the usual progressbar control.
Dim g as graphics= me.creategraphics --> e.graphics...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900