how to copy forms with controls to programmatically created projects

Locked how to copy forms with controls to programmatically created projects

  • Monday, May 07, 2012 4:07 PM
     
     
    i have programmatically created a new project from a windows application. i now want to programmatically add a form to this project that already has some data bound controls on it. what way is there to do this?

    thanks in advance

All Replies

  • Monday, May 07, 2012 4:46 PM
     
      Has Code

    how about inherit the new form from the existing one?

    public class formDerived: inherits formExisting

    ...

    End Class


    • Edited by Endotherm Monday, May 07, 2012 4:48 PM
    •  
  • Monday, May 07, 2012 5:05 PM
     
     

    hi endotherm,

    thanks a lot for replying. can i do this from my application? basically the situation is like this. my application enables a user to select a database and presents the fields on a treeview. the user can then select one table from the field and drag and drop fields onto a different form. as soon as he drops the field the application creates data bound controls on the form.

    here is where my qusetion comes in. my application then has to generate a new project (done that) and then programmatically add to the solution a form and then add to the form the control the user customized plus programmatic link to the database and create the databindings. can this be done?

    thanks again

  • Monday, May 07, 2012 6:08 PM
     
     Answered

    yes, it is possible to compile a exe on the fly, based on code files you dynamically generate. let me dig around for a sample.either way this is very ambitious, so it will take some doing to pull it off.

    since you are building the form from code files, it should be a trivial matter to change the base class by adding an inherits clause to the class definition. there may be other ways however. I'd probably approach it by having a bunch of code blocks predefined as strings and moving them into the new document as its being built.

  • Monday, May 07, 2012 6:31 PM
     
     
    much appreciated endotherm. samples would be great. thank you very much for your time.