hi friends, i am very new to c#.net.
i am developing a stand alone application.
for now i have 3 forms namely
1. Form1, this has a Next button
2. MDG_Calculations, it has one Back and one Next Buttons
3. Primary_Energy_Total_Year has one Back Button
my requirement is, when i click back button on one form, it should close the current form and should show the previous form.
i have written code for each form here.
each time i am creating objects to show the previous or next form.
this consumes lot of memory and also i see multiple instances of a single form at a time.
i thing my approach of this code is wrong.
can any body put me on track.
thanq
Form1:
______
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data.OleDb;
namespace Aim_Enduse
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MDG_Calculations mg;
private void Next_Click(object sender, EventArgs e)
{
if (mg == null)
{
mg = new MDG_Calculations();
mg.Show();
mg.Activate();
}
else
{
mg = null;
mg = new MDG_Calculations();
mg.Show();
mg.Activate();
}
//this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
MDG_Calculations
______________
namespace Aim_Enduse
{
public partial class MDG_Calculations : Form
{
public MDG_Calculations()
{
InitializeComponent();
}
Form1 f;
Primary_Energy_Total_Year pr;
private void Back_Click_1(object sender, EventArgs e)
{
this.Close();
if (f == null)
{
f = new Form1();
f.Show();
}
else
{
f.Show();
}
}
private void Next_Click(object sender, EventArgs e)
{
if (pr == null)
{
pr = new Primary_Energy_Total_Year();
pr.Show();
this.Close();
}
else
{
pr.Show();
this.Close();
}
}
}
}
Primary_Energy_Total_Year
_______________________
namespace Aim_Enduse
{
public partial class Primary_Energy_Total_Year : Form
{
MDG_Calculations mg;
public Primary_Energy_Total_Year()
{
InitializeComponent();
}
private void Back_Click(object sender, EventArgs e)
{
this.Close();
if (mg == null)
{
mg = new MDG_Calculations();
mg.Show();
}
else
{
mg.Show();
}
}
private void Primary_Energy_Total_Year_Load(object sender, EventArgs e)
{
}
}
}