Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to suspend drawing operation of a form ?

How to suspend drawing operation of a form ?

Scheduled Pinned Locked Moved C#
tutorialgraphicsquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DimaC
    wrote on last edited by
    #1

    How to suspend drawing operation of a form while a block of operations is done ? For example I need to draw some things on the form and to move some controls so that the form doesn't repaint after each of them was moved.

    K B 2 Replies Last reply
    0
    • D DimaC

      How to suspend drawing operation of a form while a block of operations is done ? For example I need to draw some things on the form and to move some controls so that the form doesn't repaint after each of them was moved.

      K Offline
      K Offline
      keith maddox
      wrote on last edited by
      #2

      I'll give this a shot but a .NET guru might be able to point out a fatal flaw in my case, but here goes. I know for sure that we could do something like this with streight WinAPI stuff but how will .NET controls handle it. Who knows. Anyway the theory works like this. The message pump for your application is dispatching messages to all of your windows and controls. Just disable the pump, do your thing with the controls (in a non-gui thread) but be carefull not to use any blocking calls that rely on a message back (the pump is off now remember), then when you are all done, turn the pump back on and issue a WM_PAINT. I've done similar things in C++ using the WinAPI without hitches (usually). Also note that the manipilation of the controls is being done in a NON-GUI thread but I think that as long as you are carefull about what you are doing to those controls, you should be alright. Be quick though because I believe windows sends some kind of a heartbeat message every so often and if it detects that your pump is down, it'll pop up a dialog saying your app has stopped responding. Not sure the mechanism winsdows is using for this but i suspect it's using a WM_NCPAINT to detect this somehow. Not sure how to turn the pump (message dispatcher) off in .NET application but I assume it's probably pretty easy. *** NOTE I assume that the controls you try to move about the form are issuing an Invalidate which causes the main form and the control to receive a WM_PAINT... Make sure you are not issuing and Invalidate or a refresh anywhere in your code that moves these around until you are all done. Probably not too much help but it'll give you a starting point. .NET GUI gurus, any ideas? Will this blow up in his face in .NET?

      D 1 Reply Last reply
      0
      • K keith maddox

        I'll give this a shot but a .NET guru might be able to point out a fatal flaw in my case, but here goes. I know for sure that we could do something like this with streight WinAPI stuff but how will .NET controls handle it. Who knows. Anyway the theory works like this. The message pump for your application is dispatching messages to all of your windows and controls. Just disable the pump, do your thing with the controls (in a non-gui thread) but be carefull not to use any blocking calls that rely on a message back (the pump is off now remember), then when you are all done, turn the pump back on and issue a WM_PAINT. I've done similar things in C++ using the WinAPI without hitches (usually). Also note that the manipilation of the controls is being done in a NON-GUI thread but I think that as long as you are carefull about what you are doing to those controls, you should be alright. Be quick though because I believe windows sends some kind of a heartbeat message every so often and if it detects that your pump is down, it'll pop up a dialog saying your app has stopped responding. Not sure the mechanism winsdows is using for this but i suspect it's using a WM_NCPAINT to detect this somehow. Not sure how to turn the pump (message dispatcher) off in .NET application but I assume it's probably pretty easy. *** NOTE I assume that the controls you try to move about the form are issuing an Invalidate which causes the main form and the control to receive a WM_PAINT... Make sure you are not issuing and Invalidate or a refresh anywhere in your code that moves these around until you are all done. Probably not too much help but it'll give you a starting point. .NET GUI gurus, any ideas? Will this blow up in his face in .NET?

        D Offline
        D Offline
        DimaC
        wrote on last edited by
        #3

        Yes, I have done it like this. Maybe there is a certain function in .NET that makes the same , but in an easier way. Something like: BeginUpdate(); .... some code here ... EndUpdate(); Between these 2 tags the controls are not repainted. Now I have made it through message filtering, i.e. I have a variable , which when set TRUE, paint messages are not allowed to be dispatched to controls contained in the form. Works well.

        1 Reply Last reply
        0
        • D DimaC

          How to suspend drawing operation of a form while a block of operations is done ? For example I need to draw some things on the form and to move some controls so that the form doesn't repaint after each of them was moved.

          B Offline
          B Offline
          benjymous
          wrote on last edited by
          #4

          SuspendLayout();

          ... do your control moving, etc

          ResumeLayout();

          -- Help me! I'm turning into a grapefruit! Buzzwords!

          D 1 Reply Last reply
          0
          • B benjymous

            SuspendLayout();

            ... do your control moving, etc

            ResumeLayout();

            -- Help me! I'm turning into a grapefruit! Buzzwords!

            D Offline
            D Offline
            DimaC
            wrote on last edited by
            #5

            SuspendLayout is a bullshit. It doesn't work as it should. It do blocks some of the controls repainting, but allows others. I have tried it many times - and it never worked as expected.

            B 1 Reply Last reply
            0
            • D DimaC

              SuspendLayout is a bullshit. It doesn't work as it should. It do blocks some of the controls repainting, but allows others. I have tried it many times - and it never worked as expected.

              B Offline
              B Offline
              benjymous
              wrote on last edited by
              #6

              Heh, fair enough.. it's worked exactly as I wanted in the places I've used it, anyway Are you using custom controls? Perhaps those aren't too well designed for C# usage, or something :~ -- Help me! I'm turning into a grapefruit! Buzzwords!

              D 1 Reply Last reply
              0
              • B benjymous

                Heh, fair enough.. it's worked exactly as I wanted in the places I've used it, anyway Are you using custom controls? Perhaps those aren't too well designed for C# usage, or something :~ -- Help me! I'm turning into a grapefruit! Buzzwords!

                D Offline
                D Offline
                DimaC
                wrote on last edited by
                #7

                Actually I use standart controls in a usercontrol. And this usercontrol is placed on a form. Anyway - I read somewhere that SuspendLayout works only a few of the controls, because many of them has their own way of painting. With standart controls, probably like buttons, labels - it may work. With textboxes it doesn't work for sure (as it's controled by Windows).

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups