Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a form1 and a button control and a panel. In each button click event the controls in the panel changes. and when i create the instance of the form it create the instance of the form which was load in the very first time. How to create the instance of the form with the latest controls in it. thanks in advance
Posted

1 solution

You can't "create an instance with the latest controls in it" if you are adding controls at run time: the form is fixed at design time and compiled into your EXE file.

To do what you want, you need to create a "basic" form, and re-add the "new" controls to it. - basically repeating what you did to get the existing form to that state.

Exactly how you do that depends on how your code works - and I can't see that!
 
Share this answer
 
Comments
thedinesh01 31-Mar-14 6:54am    
NepaliCalender frm = (NepaliCalender)Application.OpenForms["NepaliCalender"];

this code works for me.. but could you explain me what it really means :)

where NepaliCalender is name of the Form
OriginalGriff 31-Mar-14 7:01am    
See here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms(v=vs.110).aspx
Application.OpenForms is a collection of all the forms currently open in the application: supplying a name will return the form instance of that name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900