Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 ? Smile | :)
Posted 27-Sep-12 0:24am
Edited 27-Sep-12 0:38am
v5
Comments
Malli_S at 27-Sep-12 5:27am
   
Is this kind of homework?
SimonB#2149 at 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 at 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 at 27-Sep-12 13:31pm
   
Anyone who have something else to say ? :)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100