Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Everyone.

I'm working on a Calculator for a game. So i decided to try to code the calculator to be as user friendly as possible.

What i need help with is the following;

Changing the effects of another form dependent on the button i click on my mainform.
Example;

If i have two forms, MainForm and SubForm. In the MainForm i have a textbox, txtTotal, two buttons, btnAdd and btnSubtract.

In the SubForm i have a Textbox, named txtValue, two buttons, btnOK and btnCancel.

If the btnAdd from the MainForm is clicked, SubForm Loads and the value of txtValue will be ADD to the txtTotal when the btnOK is clicked.

So e.g. txtTotal already have a value of 5, in txtValue(from SubForm) i put in an additional 5 and hit ok - txtTotal will now change its value to 10.

However if the btnSubtract is clicked, SubForm Loads and the value of txtValue will be Subtracted from the txtTotal when the btnOK is clicked.

So e.g. txtTotal will now be 0, if SubForm.txtValue and MainForm.txtTotal is 5.


Also would like to know how to change a image dependent on MainForm btns. Example the btnAdd will set the background of SubForm to "C:\Some location" and the btnSubtract will set the background of SubForm to "C:\Some other Location"


also does any of you know any useful links to a guide about Class's and effects ? :)
Posted
Updated 26-Sep-12 23:38pm
v5
Comments
Malli_S 27-Sep-12 5:27am    
Is this kind of homework?
SimonB#2149 27-Sep-12 5:29am    
Sort of yes :) But not exactly because i'm adding a few extra feutures to my calculator :) But this is not a part of the specific homework :P
SimonB#2149 27-Sep-12 6:28am    
I'm really bad at Programming, but thanks for your solution OriginalGriff.. However - can i have some explanations, guides or w/e on how to do so ? :)
SimonB#2149 27-Sep-12 13:31pm    
Anyone who have something else to say ? :)

1 solution

The way to do it is to create a new event in the subform: call it NewValueAvailable or similar. Also add a string Property to the subform which returns the TextBox value.
Your Mainform them adds a handler to it when it displays the SubForm.

When the button is pressed in the SubForm, it signals the event.
The main form handler reads the new value via the SubForm property, and adds it to the total.


This way, the subform does not need to know anything about how the main form works, and vice versa.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900