Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clearing a portion of a Form
Message
 
To
13/04/2009 14:55:46
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Application:
Desktop
Miscellaneous
Thread ID:
01394032
Message ID:
01394723
Views:
36
You correct, each time that the Leave event runs it adds lbl1, lbl2, lbl3 label controls to form control collection.
Then it increment this.Controls.Count property. You can define those label (lbl1, lbl2, lbl3) objects out of this event,
because you don't need to instantiate same objects from label class each time that Leave event calls.

Move this part of your code out of Leave event:
#region Put labels on form
Label lbl1 = new System.Windows.Forms.Label();
lbl1.Text = "Name";
lbl1.Location = new System.Drawing.Point(x, y);
lbl1.Size = new System.Drawing.Size(100, 20);
lbl1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Controls.Add(lbl1);

Label lbl2 = new System.Windows.Forms.Label();
lbl2.Text = "Full Scale";
lbl2.Location = new System.Drawing.Point(x + 110, y);
lbl2.Size = new System.Drawing.Size(50, 20);
lbl2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Controls.Add(lbl2);

Label lbl3 = new System.Windows.Forms.Label();
lbl3.Text = "AlarmSource";
lbl3.Location = new System.Drawing.Point(x + 170, y);
lbl3.Size = new System.Drawing.Size(150, 20);
lbl3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Controls.Add(lbl3);
HTH
Previous
Reply
Map
View

Click here to load this message in the networking platform