Click to See Complete Forum and Search --> : Form Resizing problem??


battula32
March 14th, 2007, 07:21 AM
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



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

angedelamort
March 14th, 2007, 08:03 AM
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/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsControlClassSuspendLayoutTopic.asp