Click here to Skip to main content
13,195,564 members (66,469 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I'm making use of an extensive library of custom controls to create a dynamically constructed menu based off a data table I've received.

 All is well and fine, and I've added my controls to a FlowLayoutPanel (which had issues reordering controls embedded within due to the fact it's visibility was set to false, a whole other issue entirely) but now I wish to resize the width of all my controls based off the current selections. The logic is done and I've obtained the appropriate width all controls should be based off which buttons have been clicked.

So my question is, despite using SuspendLayout() and ResumeLayout(), my controls are still redrawn on the screen which is very aesthetically unpleasing, is there a way to resize my controls more efficiently then a for loop which iterates through a collection which has a reference to all controls within my Menu? 

Posted 28-Aug-09 9:05am
Updated 28-Aug-09 11:52am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Instead of Suspend/ResumeLayout you could try using SetRedraw. 

    public class RedrawLock : IDisposable
        #region External Method Definitions

        static public extern UInt32 SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, UInt32 lParam);
        static public extern UInt32 RedrawWindow(UInt32 hwnd, UInt32 lprcUpdate, UInt32 hrgnUpdate, UInt32 flags);

        #region Members and Constants
        const int WM_SETREDRAW = 0x000B;
        Control window = null;

        #region Constructor

        public RedrawLock(Control winToLock)
            window = winToLock;
            SendMessage(window.Handle, WM_SETREDRAW, 0, 0);


        #region IDisposable Members

        public void Dispose()
            SendMessage(window.Handle, WM_SETREDRAW, 1, 0);
            RedrawWindow(0, 0, 0, 0x181); //168, to redraw the desktop so remnants of this form disappear.


 Wrap the code in a using (new RedrawLock(this)) {} block.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171019.1 | Last Updated 17 Nov 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100