Flickering
-
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 ?
-
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 ?
-
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 ?
Hi, Otherwise you can enclose the code that deals with resizing your controls between
this.SuspendLayout()
andthis.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. -
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 ?
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.
-
Hi, Otherwise you can enclose the code that deals with resizing your controls between
this.SuspendLayout()
andthis.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. -
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.
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.
-
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.
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.
-
I didn't know that. Thanks for the info :)
Life goes very fast. Tomorrow, today is already yesterday.
-
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.
-
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.
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.
-
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.
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.
-
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.
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.
-
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.
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.
-
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.