K
kamlesh
Hey guys,
I have an app where i create a text box dynamically on a control and
user enters something and once looses focus (leave event) i remove it
from the user control.
Once i try to focus another control in the app, Control.Remove() hangs
the app and when i see the stacktrace Control. (app hangs in the
Control.GetNextControl() method.
here is code to create and remove textboxes.
am i missing something? Do i need to use GC.Collect()???
any help would be appreciated.
private void GenerateTextBox(Point location, Size size)
{
if (textArea_ == null)
{
this.SuspendLayout();
/Code for dynamically displaying the textbox for inline editing
textArea_ = new TextBox();
textArea_.Location = location;
textArea_.Size = size;
textArea_.Multiline = true;
textArea_.MaxLength = 200;
textArea_.BorderStyle = BorderStyle.FixedSingle;
textArea_.Leave += new EventHandler(this.textArea_Leave);
textArea_.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
textArea_.KeyDown += new KeyEventHandler(textArea_KeyDown);
this.Controls.Add(textArea_);
textArea_.Focus();
textArea_.BringToFront();
this.ResumeLayout();
}
}
//Method to remove the dynamic text box from the area
private void RemoveTextBox()
{
if (textArea_ != null)
{
this.SuspendLayout();
if (this.Controls.Contains(textArea_))
{
textArea_.Leave -= new
EventHandler(textArea_Leave);
this.Controls.Remove(textArea_);
textArea_.Dispose();
textArea_ = null;
}
this.ResumeLayout();
}
I have an app where i create a text box dynamically on a control and
user enters something and once looses focus (leave event) i remove it
from the user control.
Once i try to focus another control in the app, Control.Remove() hangs
the app and when i see the stacktrace Control. (app hangs in the
Control.GetNextControl() method.
here is code to create and remove textboxes.
am i missing something? Do i need to use GC.Collect()???
any help would be appreciated.
private void GenerateTextBox(Point location, Size size)
{
if (textArea_ == null)
{
this.SuspendLayout();
/Code for dynamically displaying the textbox for inline editing
textArea_ = new TextBox();
textArea_.Location = location;
textArea_.Size = size;
textArea_.Multiline = true;
textArea_.MaxLength = 200;
textArea_.BorderStyle = BorderStyle.FixedSingle;
textArea_.Leave += new EventHandler(this.textArea_Leave);
textArea_.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
textArea_.KeyDown += new KeyEventHandler(textArea_KeyDown);
this.Controls.Add(textArea_);
textArea_.Focus();
textArea_.BringToFront();
this.ResumeLayout();
}
}
//Method to remove the dynamic text box from the area
private void RemoveTextBox()
{
if (textArea_ != null)
{
this.SuspendLayout();
if (this.Controls.Contains(textArea_))
{
textArea_.Leave -= new
EventHandler(textArea_Leave);
this.Controls.Remove(textArea_);
textArea_.Dispose();
textArea_ = null;
}
this.ResumeLayout();
}