locked
change the controls position problem RRS feed

  • Question

  •  I have a form with several controls on it. As I size the form, the controls are being resized continuously. Is it possible to postpone changing the controls position until the resizing is complete?
    • Moved by CoolDadTx Wednesday, June 29, 2011 1:25 PM Winforms related (From:Visual C# General)
    Sunday, June 26, 2011 1:10 PM

Answers

  • Hello

    The idea is to do the painting on Idle. This means you simple invalidate when being sized and then do your full paint when the size completes. Here is the code that you would add to your form.

       bool idleHooked = false; 
       protected override void OnResize(EventArgs e) 
       { 
          if (!idleHooked) 
         { 
            Application.Idle += new EventHandler(OnIdle); 
         } 
       } 
     
       private void OnIdle(object s, EventArgs e) 
     
       { 
          Invalidate(); 
          PerformLayout(); 
         if (!idleHooked) 
          { 
            Application.Idle -= new EventHandler(OnIdle); 
          } 
       }
    

    Hope this can help you.
     


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Cookie_Luo Sunday, July 3, 2011 3:13 PM
    Wednesday, June 29, 2011 9:48 AM

All replies

  • Thjun

    If you have done nothing special beside dragging and dropping a control most controls are not resized.

    However, every windows forms control has a SizeChanged and a ReSize event.

    Be aware in fact is your question more for this forum.

    http://social.msdn.microsoft.com/Forums/en-US/winforms/threads


    Success
    Cor
    • Proposed as answer by RohitArora Tuesday, June 28, 2011 9:40 AM
    Tuesday, June 28, 2011 8:47 AM
  • Hello

    The idea is to do the painting on Idle. This means you simple invalidate when being sized and then do your full paint when the size completes. Here is the code that you would add to your form.

       bool idleHooked = false; 
       protected override void OnResize(EventArgs e) 
       { 
          if (!idleHooked) 
         { 
            Application.Idle += new EventHandler(OnIdle); 
         } 
       } 
     
       private void OnIdle(object s, EventArgs e) 
     
       { 
          Invalidate(); 
          PerformLayout(); 
         if (!idleHooked) 
          { 
            Application.Idle -= new EventHandler(OnIdle); 
          } 
       }
    

    Hope this can help you.
     


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Cookie_Luo Sunday, July 3, 2011 3:13 PM
    Wednesday, June 29, 2011 9:48 AM