Click here to Skip to main content
15,905,785 members
Home / Discussions / C#
   

C#

 
GeneralRe: Thread taking maximum CPU time- Pin
Karthik Kalyanasundaram12-Nov-06 0:02
Karthik Kalyanasundaram12-Nov-06 0:02 
QuestionShortcut Keys on Forms Pin
paas10-Nov-06 1:33
paas10-Nov-06 1:33 
AnswerRe: Shortcut Keys on Forms Pin
saqib8210-Nov-06 2:16
saqib8210-Nov-06 2:16 
GeneralRe: Shortcut Keys on Forms Pin
paas10-Nov-06 2:56
paas10-Nov-06 2:56 
Questiongetting the current logged in user Pin
quiteSmart10-Nov-06 0:48
quiteSmart10-Nov-06 0:48 
AnswerRe: getting the current logged in user Pin
stancrm10-Nov-06 1:51
stancrm10-Nov-06 1:51 
AnswerRe: getting the current logged in user Pin
Ashish Derhgawen10-Nov-06 2:05
Ashish Derhgawen10-Nov-06 2:05 
QuestionWorking with Objects Pin
Whatevernameyouwant10-Nov-06 0:33
Whatevernameyouwant10-Nov-06 0:33 
I am trying to get the the btnEat button to be able to access the methods for the dog object I have created but it does not exist outside of the btnCreate event. Please advise, I think its something fundamental but I can not find anywhere which answers my question, or I do not know the correct terminology for it, thanks. Wink | ;)



************************ EVENTS on button ************************



private void btnCreate_Click(object sender, EventArgs e)

{
Animal dog = new Animal();
dog.Name = txtName.Text;
lstAnimals.Items.Add(dog.Name);
lblAnimalCount.Text = "Animal Count " + Animal.Animals.ToString();
MessageBox.Show("There is currently " + Animal.foodstock.ToString() + " units of food left");
dog.eat(); //Dog Can eat here
MessageBox.Show(dog.Name + " has eaten 1 unit of food, there are now " + Animal.foodstock.ToString() + " units left");
}

private void btnEat_Click(object sender, EventArgs e)
{
// I want to make dog eat here but not sure how.
}




************************ ANIMAL CLASS ************************

class Animal

{
public Animal()
{
Animals += 1;
}

public static int foodstock = 15;
public static int Animals;

string AnimalsName;

public string Name
{
set
{
AnimalsName = value;
}

get
{
return AnimalsName;
}
}

public void eat()
{
foodstock -= 1;
}

}

******************************************************************

Thanks a million, this is a real stumbling block for me at the moment in learning Big Grin | :-D
AnswerRe: Working with Objects Pin
rah_sin10-Nov-06 0:43
professionalrah_sin10-Nov-06 0:43 
GeneralRe: Working with Objects Pin
Whatevernameyouwant10-Nov-06 0:57
Whatevernameyouwant10-Nov-06 0:57 
GeneralRe: Working with Objects Pin
rah_sin10-Nov-06 1:08
professionalrah_sin10-Nov-06 1:08 
AnswerRe: Working with Objects Pin
ednrgc10-Nov-06 3:25
ednrgc10-Nov-06 3:25 
GeneralRe: Working with Objects Pin
Whatevernameyouwant10-Nov-06 4:59
Whatevernameyouwant10-Nov-06 4:59 
GeneralRe: Working with Objects Pin
Whatevernameyouwant11-Nov-06 0:26
Whatevernameyouwant11-Nov-06 0:26 
GeneralRe: Working with Objects Pin
ednrgc13-Nov-06 2:59
ednrgc13-Nov-06 2:59 
GeneralRe: Working with Objects Pin
Whatevernameyouwant14-Nov-06 0:27
Whatevernameyouwant14-Nov-06 0:27 
QuestionCustom control border problem - WS_EX_CLIENTEDGE behavies differently depending on the WindowClass Pin
Simon P Stevens9-Nov-06 23:51
Simon P Stevens9-Nov-06 23:51 
QuestionWhich C# book to use Pin
azure0529-Nov-06 23:00
azure0529-Nov-06 23:00 
AnswerRe: Which C# book to use Pin
V.9-Nov-06 23:07
professionalV.9-Nov-06 23:07 
AnswerRe: Which C# book to use Pin
Pete O'Hanlon9-Nov-06 23:28
mvePete O'Hanlon9-Nov-06 23:28 
AnswerRe: Which C# book to use Pin
Kevin McFarlane10-Nov-06 0:48
Kevin McFarlane10-Nov-06 0:48 
AnswerRe: Which C# book to use Pin
Ashish Derhgawen10-Nov-06 2:12
Ashish Derhgawen10-Nov-06 2:12 
AnswerRe: Which C# book to use Pin
ednrgc10-Nov-06 3:33
ednrgc10-Nov-06 3:33 
QuestionDetect Sound Device in C# Pin
bahman2000b9-Nov-06 22:34
bahman2000b9-Nov-06 22:34 
QuestionLog4Net Pin
Vinoth4CS9-Nov-06 22:20
Vinoth4CS9-Nov-06 22:20 

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.