|
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();
}
}
}
|
|
|
|
|
Hi!
I'm not completely sure if I've understood your problem, but it seems to be an attribute visibility question.
You should learn about the differences between private, protected, internal, public (from MSDN, for example[^]), then the solution will dawn on you...
Regards,
mav
|
|
|
|
|
Hi, thanks for the response. Basically I have a base class Person and a child Class Athlete. In the main function I have created an instance like the Person[] athlete = new Athlete[3]; and populated it. Then I call the printData function. In console application there was no problem to see the output as follows:
for(int i = 0; i < athlete.Length ; i++)
{
athlete[i].printData();
}
How can I do the same but now to see the output in a label?
Thanks alot.
|
|
|
|
|
How can I keep a form deactivated and still accept text input? By setting the WS_EX_NOACTIVATE flag, I can put a form in background and receive mouse hit. But textbox can't accept any key.
Best Rgds.
Martin
|
|
|
|
|
No it can't. Deactivating the form prevents the input focus from being moved to it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
Thanks for the reply.
Probably I've used the wrong term. What I want to achieve is a form that is always below other normal window, even when it has the keyboard focus. I know this can be done because I've seen that in other apps. One popular example is setting Konfabulator widget window to "below".
Rgds.
marin
|
|
|
|
|
I've never used it, but I think I know what you're talking about. Hmmmm... This is going to be quite difficult because you talking about a normal app anymore. It could be that I'm just really tired, but I have no idea how you're going to get this to work, or what API's you're going to have to call to do this. I THINK this would be a Shell Extension, but I can't positively confirm it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm building something not entirely unlike the auto-resize C# Listbox [http://www.codeproject.com/cs/combobox/listbox.asp], and am trying to decide where to start. That project based their control on the Panel in order to get things like scrolling for free. The undesirable side-effect is that the derived control is a container, and is treated like such in the designer. For example, you can drop controls into their listbox and the designer will assume that the listbox (being derived from a panel) should act as a container.
So what's the workaround? Is it easier to (a) implement a scrollable view from scratch, or (b) modify a container control to no longer be treated as a container in the designer.
Any pointers on doing either would be appreciated. I have read, by the way, a bit about implementing a derived designer class, but the existing literature doesn't go into enough detail to explain anything about a control being a container or not.
|
|
|
|
|
Hi,
I am having Listview control which contains 15 rows. My problem is i want to make row 8 as read only. Is it possible in listview control.
thanks in advance
Thanks
Warm Regards
Prakash-B
|
|
|
|
|
You can use BeforeLabelEdit event
private void ListView1_BeforeLabelEdit(object sender,
System.Windows.Forms.LabelEditEventArgs e)
{
if (e.Item == 7)
{
e.CancelEdit = true;
}
}
|
|
|
|
|
Hello all!
I am using a C# program and would like to create database (SQL Server 2000) from the source code. Can anyone provide some help.
Thanks All,
Tran Dung
|
|
|
|
|
The thing to type into google is ADO.NET, you'll find a ton of examples. If you mean you want to create a database from scratch, just write a script to create a database, and execute it in C#, using ADO.NET.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
tadung wrote: I am using a C# program and would like to create database (SQL Server 2000) from the source code.
You can execute any SQL Script through SqlCommand not just the regular SELECT, INSERT, UPDATE & DELETE.
Here is an example of Running SQL scripts with a .NET application[^]
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Hi all,
My program is just a small .EXE file since i'm not using any special dll's.
1. does the user must install FRAMEWORK on his computer even though i use
just a few dll's?
2. if i use FRAMEWORK 1.xx is it ok for him to install version 2.xx ?
3. is it posible to make an installation package that will contain the
FRAMEWORK package because i dont want to send the users to microsoft
website , its not nice.
Thanks alot,
Ran.
R.Z
|
|
|
|
|
1. Yes, they need the framework.
2. It depends. You should test on 2.0 and make sure that your app is written to not be strongly associated with an older version. You can make an app require a version, or it can find the closest version. Also, if you're distributing a framework anyhow, why not make it the one you're using ?
3. Yes, I think you can download merge modules for installers. I personally write an installer app in C++ that runs the framework install and runs my MSI as well. It's possible to install the framework silently, though.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
is it posible to install few versions on the same computer?
i mean , if i will give the user the old version and he allready have a newer version will it install and use the old version along the already-installed newer version?
Ran.
R.Z
|
|
|
|
|
Yes, no problem.
Different framework versions can co-exist on the same computer peacefully.
Regards,
mav
|
|
|
|
|
sorry again,
Is there a built-in tool as part of the VISUAL STUDIO that will allow me to include the Framework as part of my installation.
i dont think i can build up something of my own..
Thanks again,
Ran.
R.Z
|
|
|
|
|
How do i set the start position of the childform that i open from my main form?
I dont' want it to be in the center of the parent form or FormStartPosition.CenterParent.
i want it to be set at 218,28 of the parent form
|
|
|
|
|
You need to set it manually, which means you need to set it AFTER you show the form. Otherwise, the framework moves it on you. So, you need to get the position of the parent form top and left, and add 218,28 to it
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Right,got that, but how do i refrence that to the parent form?
would it help if i better explain?
i've got my parent form set to load at the same point based on where you closed it. the problem i'm having is trying to refrence the location of 218,28 of the parent form, since the form isn't allways going to be located at 0,0, it maybe located on screen two or three of a multi-screen system, and the user has to move across to system.drawing.point(218,28) just to reach the new form... not sure, maybe i'm just missing your point...no punn intended
pretty much i've tried everthing i can think of(yes, very limited) and the most i've found to even come close was this.PointToClient. this was nice, it moved the new form in relation to the parent form, but the problem is it often disappears based on the parent form...basically it didn't work correctly ever.
|
|
|
|
|
The parent form has a Left property and a Top property. At least, I think it does I'd take those, and add the values to that. And, if you set the owner of the child form to be the parent, the code can go in the child form, it can move itself when it is first shown, and check it's owners position as a starting point.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Actually, that was one of the things that i didn't think of at the time of writing that last post, i actually had just testing that before you replied... having some difficulty as i having to make sure everything is in its proper place...oh syntax.....
i'll post my results in a few...hopefully!
|
|
|
|
|
hey, yah, as simple as it was, that was the solution.... why is it easier to think of the hard(or complicated) solutions before thinking of the simple ones?
must just be me....
|
|
|
|
|
Hi all.
I would like to have few files in my code, like WAV file and ICO file and i
also want to use them in the program but i dont want to have them as an extra
files inside my directory (because then things can go wrong..)
how can "attach" them in DLL or in the EXE itself ?
thanks,
Ran.
R.Z
|
|
|
|
|