Click here to Skip to main content
15,895,799 members
Home / Discussions / C#
   

C#

 
Questionbuiding an installing application Pin
Fendefa19-Jan-06 21:07
Fendefa19-Jan-06 21:07 
AnswerRe: buiding an installing application Pin
Dave Kreskowiak20-Jan-06 4:47
mveDave Kreskowiak20-Jan-06 4:47 
GeneralRe: buiding an installing application Pin
Fendefa22-Jan-06 20:44
Fendefa22-Jan-06 20:44 
GeneralRe: buiding an installing application Pin
Dave Kreskowiak23-Jan-06 1:55
mveDave Kreskowiak23-Jan-06 1:55 
GeneralRe: buiding an installing application Pin
Fendefa23-Jan-06 2:52
Fendefa23-Jan-06 2:52 
QuestionBinding an Xml file with a DropDown Control, URGENT!!!! Pin
ajmal419-Jan-06 20:25
ajmal419-Jan-06 20:25 
QuestionAdd a User Control to a TreeView Pin
tyours bobby19-Jan-06 20:07
tyours bobby19-Jan-06 20:07 
QuestionHow to use labels to pring class data Pin
Albert8319-Jan-06 19:51
Albert8319-Jan-06 19:51 
Hi, I have created the following program first as a console application. I have used the printData() method to output the data of an instance of a Person or Athlete class. I want to create a label and show the data in a label. When I try to create a label, or any similar control, that control isn't seen in the TestClasses class, and the Athlete. It is seen only in the Person constructors. 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();
}
}
}
AnswerRe: How to use labels to pring class data Pin
mav.northwind19-Jan-06 23:44
mav.northwind19-Jan-06 23:44 
GeneralRe: How to use labels to pring class data Pin
Albert8322-Jan-06 18:34
Albert8322-Jan-06 18:34 
Questiondeactivated form Pin
Martin Leung19-Jan-06 19:40
Martin Leung19-Jan-06 19:40 
AnswerRe: deactivated form Pin
Dave Kreskowiak20-Jan-06 4:21
mveDave Kreskowiak20-Jan-06 4:21 
GeneralRe: deactivated form Pin
Martin Leung20-Jan-06 14:53
Martin Leung20-Jan-06 14:53 
GeneralRe: deactivated form Pin
Dave Kreskowiak20-Jan-06 18:20
mveDave Kreskowiak20-Jan-06 18:20 
QuestionContainer versus Scrollable Pin
tylerl19-Jan-06 19:28
tylerl19-Jan-06 19:28 
QuestionListView Control Pin
PrakashBhaskar19-Jan-06 19:10
PrakashBhaskar19-Jan-06 19:10 
AnswerRe: ListView Control Pin
Werdna20-Jan-06 6:17
Werdna20-Jan-06 6:17 
QuestionCreate database SQL by coding C# Pin
tadung19-Jan-06 16:16
tadung19-Jan-06 16:16 
AnswerRe: Create database SQL by coding C# Pin
Christian Graus19-Jan-06 16:27
protectorChristian Graus19-Jan-06 16:27 
AnswerRe: Create database SQL by coding C# Pin
Colin Angus Mackay19-Jan-06 22:34
Colin Angus Mackay19-Jan-06 22:34 
QuestionFrameWork and the final software Package Pin
ranzask19-Jan-06 15:47
ranzask19-Jan-06 15:47 
AnswerRe: FrameWork and the final software Package Pin
Christian Graus19-Jan-06 16:12
protectorChristian Graus19-Jan-06 16:12 
GeneralRe: FrameWork and the final software Package Pin
ranzask20-Jan-06 2:18
ranzask20-Jan-06 2:18 
GeneralRe: FrameWork and the final software Package Pin
mav.northwind20-Jan-06 4:27
mav.northwind20-Jan-06 4:27 
GeneralRe: FrameWork and the final software Package Pin
ranzask20-Jan-06 9:55
ranzask20-Jan-06 9:55 

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.