Help for Flicker free drawing in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abdunnabisk
    New Member
    • Jan 2008
    • 17

    Help for Flicker free drawing in c#

    I am developing a program in c# where I have to show device connected each other in a dashboard.I am drawing in OnPaint event.when the user move the devices the background is flickering.beca use each time i am clearing the graphics objects.
    I tried using Doublebuffering but still not working.

    any body can help me on this.

    Thanks
    Abdun
  • leoiser
    New Member
    • Jul 2007
    • 41

    #2
    did you use the below code

    this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int |
    ControlStyles.U serPaint |
    ControlStyles.D oubleBuffer, true);

    If if does not work please let me know.You can email me for immediate reply.Thanks

    Originally posted by abdunnabisk
    I am developing a program in c# where I have to show device connected each other in a dashboard.I am drawing in OnPaint event.when the user move the devices the background is flickering.beca use each time i am clearing the graphics objects.
    I tried using Doublebuffering but still not working.

    any body can help me on this.

    Thanks
    Abdun

    Comment

    • abdunnabisk
      New Member
      • Jan 2008
      • 17

      #3
      Originally posted by leoiser
      did you use the below code

      this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int |
      ControlStyles.U serPaint |
      ControlStyles.D oubleBuffer, true);

      If if does not work please let me know.You can email me for immediate reply.Thanks
      I used that but its not working.

      Comment

      • leoiser
        New Member
        • Jul 2007
        • 41

        #4
        using System.Runtime. InteropServices ;

        #region "Avod Flickering the form"

        int paintFrozen;

        private const int WM_SETREDRAW = 0xB;

        [DllImport("User 32")]
        private static extern bool SendMessage(Int Ptr hWnd, int msg, int wParam, int lParam);

        private bool FreezePainting
        {
        get { return paintFrozen > 0; }
        set
        {
        if (value && IsHandleCreated && this.Visible)
        {
        if (0 == paintFrozen++)
        {
        SendMessage(Han dle, WM_SETREDRAW, 0, 0);
        }
        }
        if (!value)
        {
        if (paintFrozen == 0)
        {
        return;
        }

        if (0 == --paintFrozen)
        {
        SendMessage(Han dle, WM_SETREDRAW, 1, 0);
        Invalidate(true );
        }
        }
        }
        }
        #endregion


        Before drawing the image/picture put FreezePainting =true; and after finish FreezePainting= false; it will work...

        Comment

        • abdunnabisk
          New Member
          • Jan 2008
          • 17

          #5
          Originally posted by leoiser
          using System.Runtime. InteropServices ;

          #region "Avod Flickering the form"

          int paintFrozen;

          private const int WM_SETREDRAW = 0xB;

          [DllImport("User 32")]
          private static extern bool SendMessage(Int Ptr hWnd, int msg, int wParam, int lParam);

          private bool FreezePainting
          {
          get { return paintFrozen > 0; }
          set
          {
          if (value && IsHandleCreated && this.Visible)
          {
          if (0 == paintFrozen++)
          {
          SendMessage(Han dle, WM_SETREDRAW, 0, 0);
          }
          }
          if (!value)
          {
          if (paintFrozen == 0)
          {
          return;
          }

          if (0 == --paintFrozen)
          {
          SendMessage(Han dle, WM_SETREDRAW, 1, 0);
          Invalidate(true );
          }
          }
          }
          }
          #endregion


          Before drawing the image/picture put FreezePainting =true; and after finish FreezePainting= false; it will work...
          Thank you for reply.
          Actually i am drawingon a Panel not on form.same thing can be applicabe
          to Panel or not?

          Comment

          • abdunnabisk
            New Member
            • Jan 2008
            • 17

            #6
            Actually i am drawing on a Panel's OnPaint event.I have created a Graphics object
            using Graphics g=Panel.CreateG raphics();

            Each time when OnPaint event occurs i clearing the g objects and trying to
            redraw the line between devices when they are moved.

            where to Put FreezePainting= true inside OnPaintEvent.
            I put this in OnPaint event's starting line FreezePainting= true
            and OnPaint event's lastline FreezePainting= false;

            Its not drawing anything.

            Thanks

            Comment

            • leoiser
              New Member
              • Jul 2007
              • 41

              #7
              before calling the paint() u should call for FreezePainting= true

              Originally posted by abdunnabisk
              Actually i am drawing on a Panel's OnPaint event.I have created a Graphics object
              using Graphics g=Panel.CreateG raphics();

              Each time when OnPaint event occurs i clearing the g objects and trying to
              redraw the line between devices when they are moved.

              where to Put FreezePainting= true inside OnPaintEvent.
              I put this in OnPaint event's starting line FreezePainting= true
              and OnPaint event's lastline FreezePainting= false;

              Its not drawing anything.

              Thanks

              Comment

              Working...