2

I'm new to windows forms programming so my question may sound little strange.

I have created a user define control (countdown timer) now I'm creating n no of it dynamically in a form by Click of a button (Add new timer) its working well and good. Here is the Creation Code

 private void Addnew_Click(object sender, EventArgs e)
    {
       UserControl1.userControl11 = new UserControl1();      
       flowLayoutPanel1.Controls.Add(userControl11);
    }

My user control has a Reset button that reset all the content inside the user define control. it is also working, but What I want Allow user to reset all the Created timers using the “Reset All” button on the form.

too_cool
  • 1,164
  • 8
  • 24
  • There are a lot of ways to do that. Not sure where you are, stuck Does this poorly titled question help you along. http://stackoverflow.com/questions/4955769/better-way-to-find-control-in-asp-net. – Tony Hopkinson May 24 '14 at 20:29
  • @TonyHopkinson sorry but i did not understand whats there in the link u given can u please help a bit more – too_cool May 24 '14 at 20:43
  • @TonyHopkinson as you said there is a lot of way can you tell me an easy way.please help its urgent plz – too_cool May 24 '14 at 20:50
  • @TonyHopkinson one more question if you do not mind.i am using a flowLayoutPanel to show all my user define controls but when i remove /hide one user define control the Blank space remain as it is. the controls following that did not come up Can u help?? – too_cool May 24 '14 at 22:04
  • Have you got the right layout direction etc. Have a play about at design time, make sure it's configured correctly – Tony Hopkinson May 24 '14 at 23:13

1 Answers1

0

Okay one way to do this.

Create a List<UserControl1> private member on your form called say _myUserControls

In your Addnew Handler add it to the list. If you have a remove button, don't forget to remove from _myUserControls as well.

Add a Reset method to your UserControl1, that does what it needs to do.

Then in your Reset all button click handler

foreach(UserControl1 ctrl in _myUserControls)
{
   ctrl.Reset();
}

Jobs a good 'un

The answer I referred you to in comments, would be a way of finding all instances of your UserControl1 class, so you wouldn't need an internal list.

Tony Hopkinson
  • 20,172
  • 3
  • 31
  • 39
  • one more question if you do not mind.i am using a flowLayoutPanel to show all my user define controls but when i remove /hide one user define control the Blank space remain as it is. the controls following that did not come up Can u help??? – too_cool May 24 '14 at 21:59