none
Screen flickering

    Question

  • Hi,

    I have a program with 2 forms.when 2nd form activates there is flickeing.

    what to do to avoid screen flickering?

    (application.screen updating=false) not workiing

    plz help

    kuttu7


    kuttu7

    Thursday, February 23, 2012 1:19 PM

All replies

  • Hi Kuttu,

    Welcome to the MSDN Forum.

    Please just try to make two very simple forms to test this scenario. If it is still flicker, there should be something with your computer and nothing to do with your code, and then you can try this forum: http://answers.microsoft.com/en-us 

    If it is still flickering, so please post the related code here, I will try to help you out.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 27, 2012 3:53 AM
    Moderator
  • Visual Studio will suggest that DoubleBuffering your form and controls will eliminate screen flicker.  It will, but not as easily as you might wish.  Just setting the form’s “DoubleBuffered” property to “True” may not be enough.  Eventually, I put the following together using ideas from various internet sources.

    If needed, the sub “Stop_Flicker” can be called by every form in your project resulting in every control being fully “DoubledBuffered”.  If you add controls to your form, not to worry, they will be noted and processed.  If you have a control that has particularly heavy 3M (manipulation, modification and movement) activities, using “.SuspendLayout” and “.ResumeLayout” is a good idea.

    Note:  The routine “Stop_Flicker” is recursive and it needs a “stop” or “escape” procedure to prevent potential stack overflow problems.  This simple “escape” should be tailored to particular situations.

    Option Strict On

    ImportsSystem.Drawing

    ImportsSystem.Reflection

    PublicClassForm1

    PrivateSubBuffer(cnlWhat As Control)

       Dimtype As Type = cnlWhat.[GetType]()

       Dimparam As Object() = {ControlStyles.AllPaintingInWmPaint Or _

                                ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True}

       Dimflags As BindingFlags = BindingFlags.NonPublic Or BindingFlags.Instance

       Dimmethod As MethodInfo = type.GetMethod("SetStyle", flags)

       Try

         Ifmethod IsNot Nothing Then

            method.Invoke(cnlWhat, param)

          EndIf

       Catchex As Exception

          MsgBox(ex.Message, , cnlWhat.Name)   ' todo    send to error routine

       EndTry

     EndSub

    PrivateSubStop_Flicker(cnlTarget As Control)

       StaticintFlikcount As Integer = 0       ' count for escape routine

            CallBuffer(cnlTarget)

            intFlikcount += 1

            IfintFlikcount < 999 Then

                IfcnlTarget.Controls.Count > 0 Then

                    ForEachmyControl As Control In cnlTarget.Controls

                        CallStop_Flicker(myControl)

                    Next

                EndIf

            EndIf

    EndSub

    PrivateSubForm1_Load(sender As System.Object, e As System.EventArgs) _

       Handles MyBase.Load

       CallStop_Flicker(Me)

    EndSub

    If you wish to examine the results in more detail, insert (modify) and use where needed:

       method = type.GetMethod("GetStyle", flags)

       param  = {ControlStyles.AllPaintingInWmPaint Or _

                 ControlStyles.UserPaint Or ControlStyles.DoubleBuffer}

       MsgBox(method.Invoke(cnlWhat, param).ToString, , cnlWhat.Name)

    • Proposed as answer by Vinelander Tuesday, April 01, 2014 7:00 PM
    Wednesday, February 13, 2013 11:55 PM