In this lecture we are going to create the button click event a click event is the activity that someone
performs.
For example when you click a button that is regarded as an event.
So we're going to write a piece of code that does something when the event occurs.
So this is the design for our calculator.
The moment and the moment if I click on it if I run the program let me click start to run the program
for run the program and click on any of the buttons.
Nothing happens.
None of the the text or what's on the button is displayed in the result.
So we're gonna change that using a click event.
Gonna write some code behind that.
So to begin click on the button.
I'll start with the number one button and in the property window we click on the event.
This is event so an event basically something that happens to an object.
So one of the events here is a click event.
So we need to define the event.
So by giving it a name so I'm gonna call it click
on the score button.
So I've given it a name on the com button so to access the code behind this I just click on this and
to open up the code behind and also tells me see where the cup where this is flashing tells me any code
I need to write for this button click event I need to write it in here.
So this method an interactive here some someone write a piece of code.
So what I'm going to do I'm going to say I'm gonna reference the text box which is called result.
I call the result box.
You can see the intelligence is giving me guides.
I just click that does the name and it's a text box.
I'm gonna say dot text
and make it up in case.
Okay.
So as a result dot text I'm going to set that to a course to the result box
dot takes
and I'm going to add a concatenation operator concatenation means you something that will use to add
things together it's going to be a plus operator and I'm going to inside the parentheses I'm going to
include the number one
so save this.
Now I run the code.
You should see no one should appear on the calculator.
So if I click what you can see no one appears.
Notice it appears next to the 0 0 will sort out later.
You can see none of the other keys is working just the number one.
All right.
Clear that.
So what I'm going to do I'm going to combine all these functions.
This method here is click event.
I'm going to go back to our form designer and I'm going to copy this and paste it for the other buttons.
The numerical buttons so I'll start with the zero for us and come here paste and go to that I paste
and go to
paste three paste and so on for paste five paste six paste seven
and paste eight paste nine paste.
So they were all reference the same click event.
So if I run this now I'll just save all that and I'll run it.
I should be able to click on a C seven.
I'll tell you what I didn't do.
So at the moment all the all the buttons seem to be referencing this one.
So we want to change that.
And what we're going to do we going to implement a piece of code here and possum po.
They send the object references the button click event.
So we're going to create another code here.
Also type in button which is built in and then we give it a name
a button object and we going to set the value to close to the button which is button and then the sender
the sender here references to click event.
I'm going to call the sender All right.
And they're Will here would change the output so that and important that is clicked it will display
the text on the button.
So to do that we're going to replace this one with
with the button that we create here.
So to be button dot text that means it would display the text on any of the button that is clicked.
So I'll save that a run the code.
Now any of those buttons when clicked you can see the same seven even though the zero that ignore the
zero for now we will sort that out later.
Eight nine.
We're just trying to make sure all the buttons are showing one two three in to zero on the dot.
So everything is working.
We'll implement different click event for the operators and we'll figure out a code how to implement
the clever button.
So that's set for this lecture at least we've implemented a button click event.
We've got all the buttons the text on the button now displaying on the results screen when the button
is clicked.
Thanks so much for watching.
Take care.
Bye for now.