Click here to Skip to main content
15,881,248 members
Home / Discussions / C#
   

C#

 
Questionmdi child form termination Pin
edel_ong21-Jan-06 18:42
edel_ong21-Jan-06 18:42 
AnswerRe: mdi child form termination Pin
edel_ong22-Jan-06 3:28
edel_ong22-Jan-06 3:28 
Questionsystem tray icons Pin
Mridang Agarwalla21-Jan-06 17:38
Mridang Agarwalla21-Jan-06 17:38 
AnswerRe: system tray icons Pin
Stephen Hewitt21-Jan-06 17:50
Stephen Hewitt21-Jan-06 17:50 
AnswerRe: system tray icons Pin
Dave Kreskowiak21-Jan-06 18:04
mveDave Kreskowiak21-Jan-06 18:04 
GeneralRe: system tray icons Pin
CWIZO21-Jan-06 23:45
CWIZO21-Jan-06 23:45 
GeneralRe: system tray icons Pin
Dave Kreskowiak22-Jan-06 4:20
mveDave Kreskowiak22-Jan-06 4:20 
QuestionHow to use labels in windows aplications to show class data Pin
Albert8321-Jan-06 13:38
Albert8321-Jan-06 13:38 
Hi, I have created the following program first as a console application. Then I created a windows application and copied the class data there. It is shown below. In the console application, I have used the printData() method to output the data of an instance of a Person or Athlete class. I want to do the same, but now that output should be in the label.

Any help would be appreciated.


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace windowsPracticingWithClasses
{
///
/// Summary description for Form1.
///
public class Person : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;

//My instance variables
private string firstName, lastName;
private int age;
private double height, weight;
private string bankName;
private double bankAccount;
private double balance = 0;
private string squareColor;

# region Properties
//Properties
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
public double Height1
{
get { return height; }
set { height = value; }
}
public double Weight
{
get { return weight; }
set { weight = value; }
}
public string BankName
{
get { return bankName; }
set { bankName = value; }
}
public double BankAccount
{
get { return bankAccount; }
set { bankAccount = value; }
}
public double Balance
{
get { return balance ; }
set { balance = value; }
}
public string SquareColor
{
get { return squareColor ; }
set { squareColor = value; }
}
# endregion
//Custom constructor
public Person(int age, double height, double weight, string bankName, double bankAccount, double balance)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.age = age;
this.height = height;
this.weight = weight;
this.bankName = bankName;
this.bankAccount = bankAccount;
this.balance = balance;
}
//Default constructor
public Person()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

}
#region My Methods
//My Methods
public void makeDeposit(int amount)
{
balance+= amount;
}
public void makeWithdrawal(int amount)
{
balance-= amount;
}
public virtual void printData()
{
Console.WriteLine("\nProfile: \n\nAge: " + this.age);
Console.WriteLine("Height: " + this.height);
Console.WriteLine("Weight: " + this.weight);
Console.WriteLine("Bank Name: " + this.bankName);
Console.WriteLine("Bank Account: " + this.bankAccount);
Console.WriteLine("Balance: " + this.balance);
}
#endregion
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// Person
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Person";
this.Text = "Form1";
}
#endregion


}
class Athlete : Person
{

public string sport;

public Athlete(string sport) : base(23,5.6,120,"Chase",5671234,1000)
{
this.sport = sport;
}
public override void printData()
{
base.printData();
Console.WriteLine("Sport Practicing: " + this.sport);
}
};
class TestClasses
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{

Application.Run(new Person());
Person[] person = new Person[5];

person[0] = new Person(22,5.6,120,"Chase",5671234,2000);
person[0].printData();

Person[] athlete = new Athlete[3];

athlete[0] = new Athlete("Figure Skating");
athlete[0].FirstName = "Sarah";
athlete[0].LastName = "Hughes";
athlete[0].Age = 20;
athlete[0].Height1 = 5.5;
athlete[0].Weight = 120;
athlete[0].BankName = "Chase";
athlete[0].BankAccount = 434324;
athlete[0].Balance = 200;

athlete[1] = new Athlete("Martial Arts");
athlete[1].FirstName = "Kim";
athlete[1].LastName = "Chung";
athlete[1].Age = 21;
athlete[1].Height1 = 5.7;
athlete[1].Weight = 130;
athlete[1].BankName = "Citi";
athlete[1].BankAccount = 212312;
athlete[1].Balance = 300;

athlete[2] = new Athlete("Soccer");
athlete[2].FirstName = "Joe";
athlete[2].LastName = "Tribiani";
athlete[2].Age = 22;
athlete[2].Height1 = 5.6;
athlete[2].Weight = 140;
athlete[2].BankName = "Apple";
athlete[2].BankAccount = 123124;
athlete[2].Balance = 400;

for(int i = 0; i < athlete.Length ; i++)
{
athlete[i].printData();
}

Console.ReadLine();
}
}
}
Questionopen .sln Pin
fmardani21-Jan-06 13:11
fmardani21-Jan-06 13:11 
AnswerRe: open .sln Pin
Colin Angus Mackay21-Jan-06 13:20
Colin Angus Mackay21-Jan-06 13:20 
GeneralRe: open .sln Pin
Judah Gabriel Himango21-Jan-06 16:56
sponsorJudah Gabriel Himango21-Jan-06 16:56 
Questionloading the resources string in C# 2005 Pin
abstarsss21-Jan-06 13:04
abstarsss21-Jan-06 13:04 
AnswerRe: loading the resources string in C# 2005 Pin
Colin Angus Mackay21-Jan-06 13:14
Colin Angus Mackay21-Jan-06 13:14 
GeneralRe: loading the resources string in C# 2005 Pin
abstarsss21-Jan-06 19:21
abstarsss21-Jan-06 19:21 
GeneralRe: loading the resources string in C# 2005 Pin
abstarsss21-Jan-06 19:29
abstarsss21-Jan-06 19:29 
Questionget running applications Pin
galbit21-Jan-06 9:44
galbit21-Jan-06 9:44 
AnswerRe: get running applications Pin
Judah Gabriel Himango21-Jan-06 14:48
sponsorJudah Gabriel Himango21-Jan-06 14:48 
GeneralRe: get running applications Pin
galbit21-Jan-06 19:37
galbit21-Jan-06 19:37 
GeneralRe: get running applications Pin
Dave Kreskowiak22-Jan-06 9:58
mveDave Kreskowiak22-Jan-06 9:58 
Questionsaving a Private Key for future use. Pin
ranzask21-Jan-06 9:06
ranzask21-Jan-06 9:06 
QuestionHow to make owner data file? Pin
pmasknguyen21-Jan-06 6:47
pmasknguyen21-Jan-06 6:47 
AnswerRe: How to make owner data file? Pin
Dave Kreskowiak21-Jan-06 12:02
mveDave Kreskowiak21-Jan-06 12:02 
QuestionAutoSave Pin
pxp21-Jan-06 5:19
pxp21-Jan-06 5:19 
AnswerRe: AutoSave Pin
WillemM21-Jan-06 6:05
WillemM21-Jan-06 6:05 
GeneralRe: AutoSave Pin
pxp21-Jan-06 7:03
pxp21-Jan-06 7:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.