1 00:00:01,800 --> 00:00:13,710 In this lecture we are going to create the button click event a click event is the activity that someone 2 00:00:13,710 --> 00:00:15,110 performs. 3 00:00:15,210 --> 00:00:20,220 For example when you click a button that is regarded as an event. 4 00:00:20,310 --> 00:00:28,730 So we're going to write a piece of code that does something when the event occurs. 5 00:00:28,770 --> 00:00:33,210 So this is the design for our calculator. 6 00:00:33,240 --> 00:00:40,830 The moment and the moment if I click on it if I run the program let me click start to run the program 7 00:00:41,130 --> 00:00:45,070 for run the program and click on any of the buttons. 8 00:00:45,090 --> 00:00:46,050 Nothing happens. 9 00:00:46,080 --> 00:00:52,900 None of the the text or what's on the button is displayed in the result. 10 00:00:53,010 --> 00:00:56,360 So we're gonna change that using a click event. 11 00:00:56,360 --> 00:01:00,100 Gonna write some code behind that. 12 00:01:00,780 --> 00:01:02,860 So to begin click on the button. 13 00:01:02,890 --> 00:01:09,750 I'll start with the number one button and in the property window we click on the event. 14 00:01:09,750 --> 00:01:18,410 This is event so an event basically something that happens to an object. 15 00:01:18,450 --> 00:01:21,500 So one of the events here is a click event. 16 00:01:21,530 --> 00:01:23,970 So we need to define the event. 17 00:01:24,450 --> 00:01:27,990 So by giving it a name so I'm gonna call it click 18 00:01:33,860 --> 00:01:37,280 on the score button. 19 00:01:40,960 --> 00:01:51,590 So I've given it a name on the com button so to access the code behind this I just click on this and 20 00:01:52,180 --> 00:02:00,070 to open up the code behind and also tells me see where the cup where this is flashing tells me any code 21 00:02:00,070 --> 00:02:06,070 I need to write for this button click event I need to write it in here. 22 00:02:06,070 --> 00:02:09,860 So this method an interactive here some someone write a piece of code. 23 00:02:09,880 --> 00:02:20,240 So what I'm going to do I'm going to say I'm gonna reference the text box which is called result. 24 00:02:21,070 --> 00:02:22,360 I call the result box. 25 00:02:22,370 --> 00:02:24,610 You can see the intelligence is giving me guides. 26 00:02:24,630 --> 00:02:28,270 I just click that does the name and it's a text box. 27 00:02:28,270 --> 00:02:30,190 I'm gonna say dot text 28 00:02:34,380 --> 00:02:35,840 and make it up in case. 29 00:02:37,730 --> 00:02:38,690 Okay. 30 00:02:38,810 --> 00:02:48,320 So as a result dot text I'm going to set that to a course to the result box 31 00:02:52,110 --> 00:02:53,510 dot takes 32 00:02:57,330 --> 00:03:04,040 and I'm going to add a concatenation operator concatenation means you something that will use to add 33 00:03:04,130 --> 00:03:11,840 things together it's going to be a plus operator and I'm going to inside the parentheses I'm going to 34 00:03:11,840 --> 00:03:13,340 include the number one 35 00:03:16,450 --> 00:03:17,810 so save this. 36 00:03:17,830 --> 00:03:19,820 Now I run the code. 37 00:03:19,830 --> 00:03:26,110 You should see no one should appear on the calculator. 38 00:03:26,220 --> 00:03:28,640 So if I click what you can see no one appears. 39 00:03:28,660 --> 00:03:32,790 Notice it appears next to the 0 0 will sort out later. 40 00:03:32,980 --> 00:03:37,900 You can see none of the other keys is working just the number one. 41 00:03:37,900 --> 00:03:38,680 All right. 42 00:03:38,680 --> 00:03:39,480 Clear that. 43 00:03:40,180 --> 00:03:45,310 So what I'm going to do I'm going to combine all these functions. 44 00:03:45,390 --> 00:03:48,580 This method here is click event. 45 00:03:48,580 --> 00:03:58,780 I'm going to go back to our form designer and I'm going to copy this and paste it for the other buttons. 46 00:03:58,780 --> 00:04:12,460 The numerical buttons so I'll start with the zero for us and come here paste and go to that I paste 47 00:04:13,530 --> 00:04:14,640 and go to 48 00:04:17,270 --> 00:04:36,770 paste three paste and so on for paste five paste six paste seven 49 00:04:39,640 --> 00:04:47,290 and paste eight paste nine paste. 50 00:04:47,510 --> 00:04:51,530 So they were all reference the same click event. 51 00:04:51,620 --> 00:04:56,580 So if I run this now I'll just save all that and I'll run it. 52 00:04:56,600 --> 00:05:02,770 I should be able to click on a C seven. 53 00:05:03,050 --> 00:05:05,390 I'll tell you what I didn't do. 54 00:05:07,700 --> 00:05:12,890 So at the moment all the all the buttons seem to be referencing this one. 55 00:05:12,890 --> 00:05:14,820 So we want to change that. 56 00:05:14,870 --> 00:05:23,410 And what we're going to do we going to implement a piece of code here and possum po. 57 00:05:23,600 --> 00:05:27,830 They send the object references the button click event. 58 00:05:27,830 --> 00:05:32,140 So we're going to create another code here. 59 00:05:32,170 --> 00:05:39,500 Also type in button which is built in and then we give it a name 60 00:05:43,490 --> 00:05:57,140 a button object and we going to set the value to close to the button which is button and then the sender 61 00:05:57,450 --> 00:06:00,370 the sender here references to click event. 62 00:06:00,370 --> 00:06:04,370 I'm going to call the sender All right. 63 00:06:05,240 --> 00:06:12,610 And they're Will here would change the output so that and important that is clicked it will display 64 00:06:13,090 --> 00:06:16,080 the text on the button. 65 00:06:16,210 --> 00:06:23,700 So to do that we're going to replace this one with 66 00:06:27,880 --> 00:06:30,730 with the button that we create here. 67 00:06:30,760 --> 00:06:39,900 So to be button dot text that means it would display the text on any of the button that is clicked. 68 00:06:40,000 --> 00:06:42,940 So I'll save that a run the code. 69 00:06:42,940 --> 00:06:49,880 Now any of those buttons when clicked you can see the same seven even though the zero that ignore the 70 00:06:49,870 --> 00:06:52,760 zero for now we will sort that out later. 71 00:06:53,030 --> 00:06:54,840 Eight nine. 72 00:06:54,940 --> 00:07:02,470 We're just trying to make sure all the buttons are showing one two three in to zero on the dot. 73 00:07:02,620 --> 00:07:04,190 So everything is working. 74 00:07:04,240 --> 00:07:13,930 We'll implement different click event for the operators and we'll figure out a code how to implement 75 00:07:13,930 --> 00:07:15,470 the clever button. 76 00:07:15,520 --> 00:07:21,120 So that's set for this lecture at least we've implemented a button click event. 77 00:07:21,200 --> 00:07:28,660 We've got all the buttons the text on the button now displaying on the results screen when the button 78 00:07:28,900 --> 00:07:30,500 is clicked. 79 00:07:30,520 --> 00:07:31,900 Thanks so much for watching. 80 00:07:31,900 --> 00:07:32,510 Take care. 81 00:07:32,620 --> 00:07:33,250 Bye for now.