Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

windows forms and oject attributes

Status
Not open for further replies.

jimache

Programmer
Feb 26, 2003
15
US
Hi everyone,

I am a newbee in C# and I really need help.

have to do a credit card application. I have a abstract class Account which is inherited by
a RegularAccount, SilverAccount... etc, and its methods are overriden by coresponding methods in the child classes, the new objects are created by clicking a AddAccount button.

By clicking a button AddAccount on the mainForm a new form is oppened (which has combo box, and FName and LName text boxes)and then by clicking a button on the opened form an instance of Account is created( can be Regular, Silver...)...I want to be able to click another button on the mainForm(besides AddAccount) which opens a new form which displays account information(balance, payments..etc).

How can I pass the attributes of the newly created object( Account myAccount = new RegularAccount) to this form( the one that displays the account info).

TY , I really apreaciate your help.
 
As I can see you have a parent form named mainForm with two child forms, let say : NewAccountForm and AccountInfoForm.
It is depending on your requirements to decide where to store the Account objects and how and how many.
I see the following classes:
abstract class Account; and IAccount class where you put the interface that should be implemented in the derived classes such as :

double Balance(){}
void Payments(),
string Status()
class RegularAccount: Account, IAccount
class SilverAccount: Account, IAccount
etc...
//MainForm.cs

public class MainForm : System.Windows.Forms.Form
//
private Account m_Account;
private NewAccountForm m_NewAccountForm;
private AccountInfoForm m_AccountInfoForm;
public MainForm( )
{
this.IsMdiContainer = true;
// initialize mainform

}
private void AddButton_Click(object sender, System.EventArgs e)
{
m_NewAccountForm = new NewAccountForm();
m_NewAccountForm.MdiParent = this;
m_NewAccountForm.Show();
// other code here

}
private void InfoButton_Click(object sender, System.EventArgs e)
{
m_AccountInfoForm = new AccountInfoForm();
m_AccountInfoForm.MdiParent = this;
m_AccountInfoForm.Show();
// other code here to show the account info

}

//
//NewAccountForm.cs
public class NewAccountForm : System.Windows.Forms.Form
// Here you store the created account object like:
ParentForm.m_Account = new RegularAccount();

//AccountInfoForm.cs
public class AccountInfoForm : System.Windows.Forms.Form

// Here you access the Account object stored in the MainForm like:
double d = ParentForm.m_Account.Balance();

There are also other solutions but I think you can get a hint from here.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top