Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello every1!! :D
OK...I made a form in C# with some checkboxes...for example, 1 of the checkboxes says "Mustard", and when the user checks it, it's supposed to add $0.50 to a label, the problem is that where do I put the code to see if the checkbox was pressed?? do I put it after the InitializeComponent call?? where??
Thanx!! ;)El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx

Neeeeeeeevermind...what an idiot, I just had 2 double-click it in the IDE... :@ :P
But now, I have 1 more prob:Again with the public thing...but this time, here's the problem:
Price BurgerPrice = new Price();
I'm putting that inside the InitializeComponent(), just before setting the Text property of a control...
The problem is that, in the _CheckedChanged() method of another control, I try to call the BurgerPrice object, and I get an error just as if I'd never declared it... :(
What can I do now?? thanx! ;)El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx

You need to learn about scope. An object's scope determines who can access it.
If you want BurgerPrice accessable to all members of a class you can define it as a private member at the top of the class definition:
Public class MyClass
{
private Price BurgerPrice = new Price();
Public MyClass()
{
}
}If you want BurgerPrice to be accessible to other classes you can make it public, or better yet, keeping in line with ADT rules (ADT = Abstract Data Type) you should make getters and setters for that property:
Public class MyClass
{
Private Price BurgerPrice = new Price();
Public MyClass()
{
}
Public Price burgerPrice
{
get
{
return BurgerPrice;
}
set
{
BurgerPrice = value;
}
}
}Hope this helps you some. You might want to pick up C# How To Program by Dietel (they are really good books...I own the C++ How to program one and I highly recommend it too)
Chi
They mostly come at night...mostly

Yay!! that worked!! thanx!! ;)
Well, I got Microsoft Visual C# .NET by Joyce Farrell, which I got from a very expensive mail-in course...I'm almost finishing the book... :)
Thanx!! ;)El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |