473,492 Members | 4,279 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

do we need to create objects each time in c#.net

86 New Member
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)
{

}
}
}
Jul 21 '07 #1
0 858

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3035
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
10
3744
by: Nikita A. Visnevski | last post by:
Hi everyone, I am rather new to Java beans. Just picked up a book last night and started reading about them. I am building an application that allows a user to define objects with dynamic...
7
2342
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
3
1443
by: Jeff User | last post by:
Hi I want to create a rather simple object with a few string attributes to hold some database user information such as: public class UserInfo { //Basic user information for each user...
18
2307
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before....
5
1468
by: Ming Yeung | last post by:
I was wondering if .NET had the equivalent of Frames, Global Objects, and most importantly DataModules like in Delphi?
4
2174
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
2107
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
10
2082
by: CuTe_Engineer | last post by:
hii, i have cs assignment i tried to solve it but i still have many errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote the prog. i just wanna you to show me my mistakes ...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.