Results 1 to 5 of 5

Thread: Preserving form controls when creating new instance of form!!

  1. #1

    Thread Starter
    Lively Member Ksyrium's Avatar
    Join Date
    Jun 2004
    Location
    Tennessee..yes, we CAN code!!
    Posts
    80

    Preserving form controls when creating new instance of form!!

    Let's say I have two forms, FormA & FormB. When creating a new instance of FormA in FormB I lose all controls that were created in FormA at runtime. I understand this b/c I'm creating a new instance!!

    How can I preserve these controls so I can get at them from FormB? Is there another way besides creating a 'new' instance of FormA??

    Thanks.

  2. #2
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    wouldn't simply looping through FormB's control collection give you what you want

    Code:
    //FormB
    
    foreach (ctrl in FormA.Controls)
    {
        Console.Writeline (ctrl.Name) //do something meaninful here
    }

  3. #3

    Thread Starter
    Lively Member Ksyrium's Avatar
    Join Date
    Jun 2004
    Location
    Tennessee..yes, we CAN code!!
    Posts
    80
    I don't think so. I have a panel on FormA which can contain one or more usercontrols, depending on how many the user adds at runtime. If I attempt to get a 'count' of controls within the panel at runtime from FormB, I get "0" even though there have been several usercontrols added.

    ???

  4. #4
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    Originally posted by Ksyrium
    I get "0" even though there have been several usercontrols added.

    ???
    odd...works for me.

    to clarify. A form is populated with dynamic controls - you want to acess these controls from another form (the form that opens it)?
    Last edited by powdir; Sep 14th, 2004 at 05:14 AM.

  5. #5
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    Are you wanting to make a copy of the form or just copy the controls over to a new form?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width