3 forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi iam using vs 2003 .net CF1

iam having 3 forms
user will select 1st form later go 2nd form
and 3rd form to fill up application

what iam doing is

once 1stform on button click()
dim f as new form1
f.show

on 2ndform on button click()
dim f as new form2
f.show

now iam 3 rd form
once the user save data in xml.

he will click cross button of 3form and 2form
to go back first form

and later the process countinues again

1stform->2ndform->3rdform


which is the best way to save memory
or anything i should close.
any mistakes....
or ease way....

thanks
 
In order to keep track of the forms you are showing:
1. It's better to use the Form.ShowDialog method instead of Form.Show to
ensure the order in which the user moves from one form to the other.
2. Set the MinimizeBox property of the form to False.
3. It's a good practice to create a class that keeps one reference to each
of the application forms. This way ensures you that you always keep track of
the same instances of the forms, and there can never be "floating" forms in
your applications that might get lost and cause unpredictable behaviour of
the application.
 
Alternatively you could use something like

static void Navigate (Form from, Form to) {
to.Show();
from.Hide();
}

preventing multiple entries showing up in the device's taskmanager.
 
hi how to create
create a class that keeps one reference to each
of the application forms.

as in 2nd form iam loading dataset
like public shared ds as new dataset
and reading the same data again....
in 3rd form...

after closing 3rd form go back to 1st form
but i think it will be overloaded, because the everyting loading the
dataset...
how to improve performance

thanks
 
using System;
using System.Windows.Forms;

public sealed class MyApp {

MyApp () {}

static Form current;

public static void Start (Form f) {
current = f;
Application.Run(f);
}

public static void NavigateTo (Form f) {
f.StartPosition = FormStartPosition.Manual;
f.Bounds = current.Bounds;
f.Show();
current.Hide();
current = f;
}

public static void Exit () {
Application.Exit();
}

}

sealed class MyForm: Form {

Button b;
Form next;

public MyForm () {
this.InitializeComponent();
}

protected override void OnClosed (EventArgs e) {
MyApp.Exit();
}

void b_Click (object source, EventArgs e) {
MyApp.NavigateTo(next);
}

void InitializeComponent () {
b = new Button();
b.Click += new EventHandler(b_Click);
this.Controls.Add(b);
}

public void ConnectTo (Form next) {
this.next = next;
this.b.Text = next.Text;
}

}

sealed class Hello {

Hello () {}

public static void Main () {
MyForm one = new MyForm();
one.Text = "One";
MyForm two = new MyForm();
two.Text = "Two";
MyForm three = new MyForm();
three.Text = "Three";
one.ConnectTo(two);
two.ConnectTo(three);
three.ConnectTo(one);
MyApp.Start(one);
}

}
 
Back
Top