selecting custom controls in a panel

  • Thread starter Thread starter Stephen.Schoenberger
  • Start date Start date
S

Stephen.Schoenberger

I have a windows form that has a panel on it. At runtime a custom
control is added multiple times to this panel. (anywhere from 1-50 of
them are added). I am trying to figure out how I can "select" just one
of these controls. I want this to lead to the ability to move the
controls up and down and insert/delete controls based on the current
control "selected"...

Any help/advise?

Thanks.
 
the added custom controls are added to the panel Controls collection.
you can look for through the collection look for specific control type
or name

foreach(Control child in panelObj.Controls)
{

if ( child is TextBox && TextBox.Name = "X" )
..........

}
 
Have you looked at adding a click delegate/eventhandler on control creation
so that when you select the custom control you can carry out the required
action.
 
Stephen,
When you dynamically create the control, bind the OnGotFocus event to a
method. When the control is selected, the control reference is sent in the
sender of the fired event. Just cast the sender object to your control type
using
obj1 x = sender as obj1; (where obj1 is the type)
and then check if x is null. If not null then the cast was successful, and
you can do work on the control.

Rick D.
Contractor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top