Click here to Skip to main content
13,147,037 members (59,481 online)
Rate this:
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.

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 26-Sep-12 23:24pm
Updated 26-Sep-12 23:38pm
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

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2017
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