In .NET CF we are bounded by a lot of limitations mostly of them are memory and speed related.
When I was new to CF, I faced problem while developing an MDI application.
The basic problem while developing multiple document application is that as soon as one closes the form called first in the application, the whole application will be closed. Some how I got a solution which I feel very easy to implement .Just a simple trick!!!
When you want to develop an application I feel that it is better to create a mother class where you can define variables common to all the forms which give the dimension of maintainability to the code. This mother class will have the instances of all the forms and all the forms will have instance of this mother class. This way it will be easy to interlink all the forms with Mother Class as well as child forms themselves.
The following code shows how to create the controlling mother class:
public class MotherClass
public Form1 f1;
public Form2 f2;
public Form3 f3;
public mainscreen mScreen;
mScreen = new mainscreen(this);
static void Main()
MotherClass mc = new MotherClass();
So now first of all the main screen will appear which you can compare with the MDI parent form in the Frame work. Here one can provide the options of opening of remaining child forms. In the main form I have provided one of the most optimal solutions for form opening in the following lines of code.
private void button1_Click(object sender, EventArgs e)
if (mc.f1 == null)
mc.f1 = new Form1();
In this code when one clicks on button1 for opening form1, it checks whether the form is being opened first time by checking against null. If yes then it creates the instance that time only. So no instance creation for the forms which are never clicked in the application. Instead of creating instance of the form in start (i.e. in mother class) where it can increase the loading time of application, one should create the instance of form only when needed.
After opening a form, providing it all the input, when one closes the form, it disappears in background instead of getting closed .It is due to the following lines of code where I cancels the closing of the form and brings the main screen in front.
private void Form1_Closing(object sender, CancelEventArgs e)
e.Cancel = true;
Now if the user again clicks the button1 to open the form1, this time the object is already exists , so it brings the form in from without going in the if loop by executing show function of the form.
But remember one thing that as soon as one closes the main screen, the application will exit by itself as this time we have not cancelled the closing event of main screen.
1) In this method the loading time of the application reduces because we are not creating forms intially, it is created only when one need to open that particular form.
2) Once the form is opened , it remains opened .We can play the game of hide and seek till the application ends, just by cancelling the closing of the form and bringing the mainscreen in from at right moment.
3) The mother class provides the opportunity to declare the variables which are used in all the forms or in most of the forms similar to the global variables in C++ which are absent in .Net CF. And just with the instance of Mother class those variables can be used in that particular form.
4) Due to creating the instance of the Mother class to each form , it is easier to call the other forms also in a particular one.For e.g. in form one we can call
which will bring the form2 in front instead of mainscreen if it already exists.
Implementation of the multiple document interface can be done in a lot of ways but this trick made my application behave in one of the optimized way .The maintainability is also easy.