Click here to Skip to main content
15,899,937 members
Home / Discussions / C#
   

C#

 
GeneralRe: how i chang culture in control panel Pin
Guffa22-Jan-06 4:24
Guffa22-Jan-06 4:24 
QuestionAccess controls from Thread Pin
tray_gator21-Jan-06 23:37
tray_gator21-Jan-06 23:37 
AnswerRe: Access controls from Thread Pin
CWIZO21-Jan-06 23:43
CWIZO21-Jan-06 23:43 
GeneralRe: Access controls from Thread Pin
tray_gator21-Jan-06 23:58
tray_gator21-Jan-06 23:58 
AnswerRe: Access controls from Thread Pin
mav.northwind22-Jan-06 0:02
mav.northwind22-Jan-06 0:02 
JokeRe: Access controls from Thread Pin
tray_gator22-Jan-06 0:28
tray_gator22-Jan-06 0:28 
GeneralRe: Access controls from Thread Pin
CWIZO22-Jan-06 2:23
CWIZO22-Jan-06 2:23 
GeneralRe: Access controls from Thread Pin
tray_gator22-Jan-06 3:25
tray_gator22-Jan-06 3:25 
QuestionHow to pass reference parameter to unmanaged dll Pin
Sriinii21-Jan-06 20:41
Sriinii21-Jan-06 20:41 
AnswerRe: How to pass reference parameter to unmanaged dll Pin
[Marc]22-Jan-06 10:21
[Marc]22-Jan-06 10:21 
GeneralRe: How to pass reference parameter to unmanaged dll Pin
Ravi Bhavnani22-Jan-06 11:25
professionalRavi Bhavnani22-Jan-06 11:25 
Questioncannot launch exe from windows service?? Pin
mdroz821-Jan-06 20:14
mdroz821-Jan-06 20:14 
AnswerRe: cannot launch exe from windows service?? Pin
turbochimp21-Jan-06 20:38
turbochimp21-Jan-06 20:38 
GeneralRe: cannot launch exe from windows service?? Pin
mdroz821-Jan-06 20:57
mdroz821-Jan-06 20:57 
GeneralRe: cannot launch exe from windows service?? Pin
turbochimp21-Jan-06 21:03
turbochimp21-Jan-06 21:03 
GeneralRe: cannot launch exe from windows service?? Pin
mdroz822-Jan-06 4:38
mdroz822-Jan-06 4:38 
QuestionTab Control problem Pin
Ph@ntom21-Jan-06 19:45
Ph@ntom21-Jan-06 19:45 
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();
}
}
}

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.