"to find performance to be an issue. "
I assume you are referring to the drawingloading time? We
see this. First
time you open a screen with lots of controls, it takes 1-2
seconds.
Subsequent times it's instant.
-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailto OTNET-WI
NFORMS DISCUSS.DEVELOP.COM]On Behalf Of
Peter Ritchie
Sent: Friday, November 10, 2006 11:26 AM
To: DOTNET-WINFORMS DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] How to access controls made
at runtime
Hi Steve. Some architectural advice... If you start having
much more
than 20 controls on a form you're going to find performance
to be an
issue. It sounds like the more complex the drawing the
greater number of
controls your form will have. While there's really no
"physical" limit to
control count, there's a realistic limit because of update
and paint
overhead.
You'll need to make sure the Name property of your
dynamically added
controls is set and unique then you can use the
Form.Controls collection
to get at the objects. So, you'd create a control something
like this:
TextBox newTextBox = new TextBox();
newTextBox.Name = "TextBoxName"; //*
newTextBox.Location = new Point(165, 166);
newTextBox.Size = new Size(100, 20);
this.Controls.Add(newTextBox);
Then access that control in a button click handler like
this:
private void button1_Click ( object sender, EventArgs e )
{
TextBox textBox = this.Controls["TextBoxName"]
as TextBox;
if(textBox != null)
{
textBox.Text = "ding";
}
}
|