dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] Flickering in user control but NOT with similar code painting a WinForms panel

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2016
    Posts
    21

    Resolved [RESOLVED] Flickering in user control but NOT with similar code painting a WinForms panel

    I have been successfully drawing 6 analog gauges, each in their own panel on a form, by handling the panel's paint event. They look fantastic and have no flicker. I am updating them every 100 milliseconds. I tried to improve on this by creating a user control with a panel in it and adding some properties so that I could more easily create these analog gauges and use them in several projects. I am again handling the panels' paint event to draw the gauge. However, when I create 6 of these custom gauge controls and add them to a form, they flicker horribly. I have tried double-buffering which did not help or made it worse. Is there something fundamentally different about the way a user control works that is causing the flickering? I may just try to create a new class that inherits from panel and add my custom properties to it.

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,252

    Re: Flickering in user control but NOT with similar code painting a WinForms panel

    Quote Originally Posted by tigerWereWolfMonkey View Post
    I have tried double-buffering which did not help or made it worse. Is there something fundamentally different about the way a user control works that is causing the flickering? I may just try to create a new class that inherits from panel and add my custom properties to it.
    Try a picbox instead of a panel, IIRC a picbox is buffered by default, but if you need to use a panel try making a class for it, and set DoubleBuffered in the constructor,..

    Code:
    Public Class myPanel
        Inherits Panel
    
        Public Sub New()
            Me.DoubleBuffered = True
        End Sub
    
    End Class
    If you still have issues maybe post how/where your drawing/painting, etc, maybe someone else can help.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2016
    Posts
    21

    Re: Flickering in user control but NOT with similar code painting a WinForms panel

    Thanks for the response. Can you explain why it would not be flickering in a simple panel in my project but flickering in the panel in the custom user control?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2016
    Posts
    21

    Red face Re: Flickering in user control but NOT with similar code painting a WinForms panel

    Edgemeal, You were spot on. Using a picture box instead of a panel worked. Also, I was mistaken about using a panel in my project. What I had working before I created the user control WAS using a picture box (inside a panel) and not a simple panel. (Which is why it was working so nicely). I need sleep!

  5. #5
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Flickering in user control but NOT with similar code painting a WinForms panel

    Quote Originally Posted by tigerWereWolfMonkey View Post
    Thanks for the response. Can you explain why it would not be flickering in a simple panel in my project but flickering in the panel in the custom user control?
    There's no reason the user control should flicker, unless you do not have double buffering enabled. Painting to a panel, of course, potentially cause flickering. A user control would be a good candidate for a control which is used repeatedly, encapsulating all the code necessary to draw the control.

    You also would not need to put any container on the control: just use the paint event of the control itself (no picture box, panel, etc.)
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width