CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    105

    Form Resizing problem??

    I have some strange problem.

    This prbolem is occurred when I click on Maximize and restore buttons.
    If I click on Maximize button, form is maximized, If I click on restore buttom Form_resize event is invoking continuously and it is going into forever loop.

    Here by I am givng sample code

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Resizing
    {
        public partial class Form1 : Form
        {
            private int m_lWidth=850;
            private bool m_bTemp = false;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                m_bTemp = true;
                this.Width = 730;
                
            }
    
            private void Form1_Resize(object sender, EventArgs e)
            {
                if (this.WindowState != FormWindowState.Minimized)
                {
                    if (!m_bTemp)
                    {
                        if (m_lWidth > this.Width && this.WindowState != FormWindowState.Maximized)
                            this.Width = m_lWidth;
                    }
                    m_bTemp = false;
                }
            }
        }
    }

    Here I set minimum size as (730/540)
    If i click on button I set from width as 730. If I maximixe and resotre again I am checking Form width. If form width is less than 850 I am setting from width as 850. then resize event is going into for ever loop.

    Similar type condition is there in My application

    regards
    Ravi

  2. #2
    Join Date
    Mar 2007
    Posts
    59

    Re: Form Resizing problem??

    hello,
    you modify the this.Width property. When you do that, the resize delegate is called. try with a SuspendLayout/ResumeLayout when modifying the size.

    more information here on the method
    http://msdn.microsoft.com/library/de...ayoutTopic.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured