<p>My app has many controls on its surface, and more are added dynamically at runtime.</p>

<p>Although i am using tabs to limit the number of controls shown, and double-buffering too, it still flickers and stutters when it has to redraw (resize, maximize, etc).</p>

<p>What are your tips and tricks to improve WinForms app performance?</p>

[{'answer_id': 44933, 'author': 'Jim Harte', 'author_id': 4544, 'author_profile': 'https://Stackoverflow.com/users/4544', 'pm_score': 1, 'selected': False, 'text': '<p>Are you making good use of <code>SuspendLayout()</code> and <code>ResumeLayout()</code>?</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout(VS.80).aspx</a></p>\n'}, {'answer_id': 44934, 'author': 'viggity', 'author_id': 4572, 'author_profile': 'https://Stackoverflow.com/users/4572', 'pm_score': 4, 'selected': True, 'text': '<p>I know of two things you can do but they don\'t always apply to all situations.</p>\n\n<ol>\n<li><p>You\'re going to get better performance if you\'re using absolute positioning for each control (myNewlyCreatedButton.Location.X/Y) as opposed to using a flow layout panel or a table layout panel. WinForms has to do a lot less math trying to figure out where controls should be placed.</p></li>\n<li><p>If there is a single operation in which you\'re adding/removing/modifying a lot of controls, call "SuspendLayout()" on the container of the affected controls (whether it is a panel or the whole form), and when you\'re done with your work call "ResumeLayout()" on the same panel. If you don\'t, the form will have to do a layout pass each and every time you add/remove/modify a control, which cost a lot more time.  see: <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout(VS.80).aspx</a></p></li>\n</ol>\n\n<p>Although, I\'m not sure how these approaches could apply when resizing a window.</p>\n'}, {'answer_id': 44945, 'author': 'Brian Ensink', 'author_id': 1254, 'author_profile': 'https://Stackoverflow.com/users/1254', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p>Although, I'm not sure how these approaches could apply when resizing a window.</p>\n</blockquote>\n\n<p>Handle the ResizeBegin and ResizeEnd events to call SuspendLayout() and ResumeLayout().  These events are only on the System.Windows.Form class (although I wish they were also on Control).</p>\n"}, {'answer_id': 45287, 'author': 'Grey Panther', 'author_id': 1265, 'author_profile': 'https://Stackoverflow.com/users/1265', 'pm_score': 2, 'selected': False, 'text': '<p>Although more general than some of the other tips, here is mine:</p>\n\n<p>When using a large number of "items", try to avoid creating a control for each one of them, rather reuse the controls. For example if you have 10 000 items, each corresponding to a button, it is very easy to (programatically) create a 10 000 buttons and wire up their event handlers, such that when you enter in the event handler, you know exactly which element you must work on. However it is much more efficient if you create, lets say, 500 buttons (because you know that only 500 buttons will be visible on the screen at any one time) and introduce a "mapping layer" between the buttons and the items, which dynamically reassigns the buttons to different items every time the user does something which would result in changing the set of buttons which should be visible (like moving a scrollbar for example).</p>\n'}]
['https://Stackoverflow.com/questions/44914', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1587/']