Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i count the number of instances created in an application?

eg:
there are 2 forms : form1, form2
There is a button on form1. When i click on it a new form of type form2 is created.

i want to display a message box displaying the number of form2 instances created, every time the button is clicked.

any help plz?
Posted

Keep a variable that increments the count everytime a new form2 instance is created.
 
Share this answer
 
To add to the previous answer, you would do that by incrementing that variable in the form's constructor, as that is called for every instance created.
 
Share this answer
 
Declare static variable and increment it on every button click, and show it on message box :)
 
Share this answer
 
v2

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