Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)

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
Updated 28-Aug-09 11:52am
v2

1 solution

Instead of Suspend/ResumeLayout you could try using SetRedraw. 

C#
    public class RedrawLock : IDisposable
    {
        #region External Method Definitions

        [DllImport("user32.dll")]
        static public extern UInt32 SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, UInt32 lParam);
        [DllImport("user32.dll")]
        static public extern UInt32 RedrawWindow(UInt32 hwnd, UInt32 lprcUpdate, UInt32 hrgnUpdate, UInt32 flags);
        #endregion

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

        #region Constructor

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

        #endregion

        #region IDisposable Members

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

        #endregion
    }

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

 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900