UserControl issue - creating a property which is a collection of controls

G

Guest

H
I have created a custom text box control and custom label control (Both inherited controls from the standard .Net controls

I would like to be able to relate several of the label controls to a single text box control, so that I can have code which automatically clears the labels when I clear the control. I would like to define these labels as a property of the text box control so that I can add 1 or many related labels to the contro

Does anyone know how I would do this

Many thank
Siobhan
 
J

Jeff Gaines

Hi
I have created a custom text box control and custom label control (Both inherited controls from the standard .Net controls)

I would like to be able to relate several of the label controls to a single text box control, so that I can have code which automatically clears the labels when I clear the control. I would like to define these labels as a property of the text box control so that I can add 1 or many related labels to the control

Does anyone know how I would do this?

Many thanks
Siobhan

Sounds like fun.

How about creating your TextBox with an array of labels as a
parameter:

public MyTextBox(Label[] lables)
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

m_lblArray = lables;
}

m_lblArray would be a module wide parameter in the MyTextBox
class. You can then run a foreach over them to clear their text.

If, for instance, they were all on one form or other container
you could construct the class with that container as a parameter
and then run a foreach over the container.
 

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

Top