Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB Windows VB10.0 WinForm

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 10:05am
Edited 28-Aug-09 12:52pm
v2

1 solution

Rate this: bad
good
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

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

  Permalink  

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

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 17 Nov 2009
Copyright © CodeProject, 1999-2014
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