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. Flickering

Flickering

Scheduled Pinned Locked Moved C#
question
14 Posts 4 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.
  • P Offline
    P Offline
    peropata
    wrote on last edited by
    #1

    Hi, I have a form, with 40 controls, that change size while form is resized. I tried to find solution for flickering, but none of them realy worked. (like: OnPaintBackground, protected override CreateParams CreateParams, DoubleBuffered = true ...) Is there any way to prevent this annoying flickering ?

    M P L 3 Replies Last reply
    0
    • P peropata

      Hi, I have a form, with 40 controls, that change size while form is resized. I tried to find solution for flickering, but none of them realy worked. (like: OnPaintBackground, protected override CreateParams CreateParams, DoubleBuffered = true ...) Is there any way to prevent this annoying flickering ?

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      Your not manually coding the resize of the controls on the form resize event are you? You should use Anchor property of the controls, maybe with a layout grid of some kind dependign on your needs

      Life goes very fast. Tomorrow, today is already yesterday.

      1 Reply Last reply
      0
      • P peropata

        Hi, I have a form, with 40 controls, that change size while form is resized. I tried to find solution for flickering, but none of them realy worked. (like: OnPaintBackground, protected override CreateParams CreateParams, DoubleBuffered = true ...) Is there any way to prevent this annoying flickering ?

        P Offline
        P Offline
        phil o
        wrote on last edited by
        #3

        Hi, Otherwise you can enclose the code that deals with resizing your controls between this.SuspendLayout() and this.ResumeLayout(true) (this is the form). It will prevent the form from redrawing itself everytime you change a control's property. Instead, it will redraw at the end of the operation, when new values will all be computed. This should remove flickering. Regards.

        M 1 Reply Last reply
        0
        • P peropata

          Hi, I have a form, with 40 controls, that change size while form is resized. I tried to find solution for flickering, but none of them realy worked. (like: OnPaintBackground, protected override CreateParams CreateParams, DoubleBuffered = true ...) Is there any way to prevent this annoying flickering ?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          You get more flickering when you have more and/or more complex controls on a WinForm. 40 is quite a lot; are some of them list controls (ListBox, DataGridView, TreeView, ...)? are they databound? There are some precautions you can take: - make complex controls double-buffered (works often fine for complex controls); - make the Form double-buffered (hasn't really ever worked for me); - make sure you don't create a lot of objects while painting controls (assuming some are user-drawn); - avoid background images; - avoid transparency; - avoid slow data accesses (database, network, ...) to fill your controls. However the main guide line is: keep your forms simple, the user will appreciate it in many ways. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          M 1 Reply Last reply
          0
          • P phil o

            Hi, Otherwise you can enclose the code that deals with resizing your controls between this.SuspendLayout() and this.ResumeLayout(true) (this is the form). It will prevent the form from redrawing itself everytime you change a control's property. Instead, it will redraw at the end of the operation, when new values will all be computed. This should remove flickering. Regards.

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            I didn't know that. Thanks for the info :)

            Life goes very fast. Tomorrow, today is already yesterday.

            P 1 Reply Last reply
            0
            • L Luc Pattyn

              You get more flickering when you have more and/or more complex controls on a WinForm. 40 is quite a lot; are some of them list controls (ListBox, DataGridView, TreeView, ...)? are they databound? There are some precautions you can take: - make complex controls double-buffered (works often fine for complex controls); - make the Form double-buffered (hasn't really ever worked for me); - make sure you don't create a lot of objects while painting controls (assuming some are user-drawn); - avoid background images; - avoid transparency; - avoid slow data accesses (database, network, ...) to fill your controls. However the main guide line is: keep your forms simple, the user will appreciate it in many ways. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              M Offline
              M Offline
              musefan
              wrote on last edited by
              #6

              Luc Pattyn wrote:

              - make sure you don't create a lot of objects while painting controls (assuming some are user-drawn);

              I second that, writing efficient paint events/overrides can be critical. Oh, and a tip while one the subject... don't forget to dispose local Pens and Brushes (thou a better tip would be to use a global instance of them in the first place ;) )

              Life goes very fast. Tomorrow, today is already yesterday.

              L 1 Reply Last reply
              0
              • M musefan

                Luc Pattyn wrote:

                - make sure you don't create a lot of objects while painting controls (assuming some are user-drawn);

                I second that, writing efficient paint events/overrides can be critical. Oh, and a tip while one the subject... don't forget to dispose local Pens and Brushes (thou a better tip would be to use a global instance of them in the first place ;) )

                Life goes very fast. Tomorrow, today is already yesterday.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                yes, I normally recommend that but lacking an indication of any owner-drawing, I omitted it this time. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                1 Reply Last reply
                0
                • M musefan

                  I didn't know that. Thanks for the info :)

                  Life goes very fast. Tomorrow, today is already yesterday.

                  P Offline
                  P Offline
                  phil o
                  wrote on last edited by
                  #8

                  You're welcome :)

                  modified on Thursday, December 2, 2010 10:52 AM

                  L 1 Reply Last reply
                  0
                  • P phil o

                    You're welcome :)

                    modified on Thursday, December 2, 2010 10:52 AM

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    this is my answer to "does it really work?" which now is gone... that depends. AFAIK it stops intermediate layout operations when items get added to a bigger item, such as ListViewItems to a ListView; however I don't expect it to have much influence on flicker reduction while resizing a form, unless their is a strong correlation between size and layout, as in a TableLayoutPanel or some kind of flow-lauyout thing. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    P M 2 Replies Last reply
                    0
                    • L Luc Pattyn

                      this is my answer to "does it really work?" which now is gone... that depends. AFAIK it stops intermediate layout operations when items get added to a bigger item, such as ListViewItems to a ListView; however I don't expect it to have much influence on flicker reduction while resizing a form, unless their is a strong correlation between size and layout, as in a TableLayoutPanel or some kind of flow-lauyout thing. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                      P Offline
                      P Offline
                      phil o
                      wrote on last edited by
                      #10

                      Sorry, I removed the question because I noticed that I was not talking with the one that opened this post a few minutes after posting ^^ I've used this trick a couple of times and it did work well for me. I was wondering if it had done the trick to this particular issue.

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        this is my answer to "does it really work?" which now is gone... that depends. AFAIK it stops intermediate layout operations when items get added to a bigger item, such as ListViewItems to a ListView; however I don't expect it to have much influence on flicker reduction while resizing a form, unless their is a strong correlation between size and layout, as in a TableLayoutPanel or some kind of flow-lauyout thing. :)

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                        M Offline
                        M Offline
                        musefan
                        wrote on last edited by
                        #11

                        I think in this case you have 40 controls manual resized on the Form resize event - that would be 40 from re-draws per each Form Resize event fired. I was assuming that susspending the layout would reduce this to only 1 re-draw per each Form Resize event fired. At least I hope this is the case as I may find this useful if I revisit some code from a while back (I solved in other ways but would like to try this method at some point)

                        Life goes very fast. Tomorrow, today is already yesterday.

                        P 1 Reply Last reply
                        0
                        • M musefan

                          I think in this case you have 40 controls manual resized on the Form resize event - that would be 40 from re-draws per each Form Resize event fired. I was assuming that susspending the layout would reduce this to only 1 re-draw per each Form Resize event fired. At least I hope this is the case as I may find this useful if I revisit some code from a while back (I solved in other ways but would like to try this method at some point)

                          Life goes very fast. Tomorrow, today is already yesterday.

                          P Offline
                          P Offline
                          peropata
                          wrote on last edited by
                          #12

                          I was just on my way from work, so I didn't responde earlier. I was trying to create a matrix of fields, so when you click or hover over a field some event is raised. I will probably draw the whole matrix on bitmap and use double buffering and create events based on mouse position.

                          L 1 Reply Last reply
                          0
                          • P peropata

                            I was just on my way from work, so I didn't responde earlier. I was trying to create a matrix of fields, so when you click or hover over a field some event is raised. I will probably draw the whole matrix on bitmap and use double buffering and create events based on mouse position.

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #13

                            if a large number of controls have similar functionality and are laid out in a grid (e.g. a virtual keyboard), then that would be the right approach; it is often referred to as "lightweight controls" and I use it a lot. You can still use a little class to represent each of the light controls, then iterate over them in your overall mouse handlers and OnPaint handler. :)

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at them.

                            P 1 Reply Last reply
                            0
                            • L Luc Pattyn

                              if a large number of controls have similar functionality and are laid out in a grid (e.g. a virtual keyboard), then that would be the right approach; it is often referred to as "lightweight controls" and I use it a lot. You can still use a little class to represent each of the light controls, then iterate over them in your overall mouse handlers and OnPaint handler. :)

                              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                              Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at them.

                              P Offline
                              P Offline
                              peropata
                              wrote on last edited by
                              #14

                              I will go with "lightweight controls". I guess, I was just lazy and was looking for shortcuts. :-D

                              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