1
00:00:01,020 --> 00:00:10,910
In this lecture we are going to add code that will allow us to save our droid.

2
00:00:11,130 --> 00:00:16,160
So click on the design view and in the file here.

3
00:00:16,170 --> 00:00:17,840
File option here.

4
00:00:17,850 --> 00:00:23,070
I'm just gonna change this option.

5
00:00:23,070 --> 00:00:26,590
I'm going to just I'm going to activate only one of them.

6
00:00:26,610 --> 00:00:34,080
The Save balance leave the other one so you can also if you want to create more many options you can

7
00:00:34,120 --> 00:00:37,530
and then just implement the code the same way.

8
00:00:37,600 --> 00:00:43,330
So I'm just gonna double click on this to give me the Skeletor code.

9
00:00:43,440 --> 00:00:56,010
So this is the event the method that will respond to when the button the save button is clicked.

10
00:00:56,700 --> 00:01:05,890
What we need to do also we need to add is save file dialog so click on the tool box and on the dialogues.

11
00:01:06,210 --> 00:01:09,320
That's an option for self file dialog.

12
00:01:09,870 --> 00:01:14,370
So just double click on that and that should be there.

13
00:01:14,370 --> 00:01:17,200
So this is the save file dialog.

14
00:01:17,460 --> 00:01:25,020
So we're going to incorporate that into our code so that when the files save us option is pressed it

15
00:01:25,020 --> 00:01:27,750
will reference this dialog.

16
00:01:28,350 --> 00:01:30,170
So let me pop back into the code.

17
00:01:30,180 --> 00:01:33,950
So this is the code here.

18
00:01:34,260 --> 00:01:52,110
So to begin I you typing the save file dialog and I'm going to say I'm going to set that to the save

19
00:01:52,110 --> 00:01:54,080
file.

20
00:02:02,570 --> 00:02:07,840
So I'm going to create a will references save file dialogue.

21
00:02:07,850 --> 00:02:16,250
We just added on and set that to a quote set a new instance of that variable to do that type in new

22
00:02:17,180 --> 00:02:18,290
and then save

23
00:02:22,130 --> 00:02:23,740
type save file dialog.

24
00:02:26,640 --> 00:02:30,370
So we're setting it to a course to do that.

25
00:02:30,400 --> 00:02:34,120
So this will create a new instance of that.

26
00:02:34,120 --> 00:02:40,600
The next thing I want to do want to create a variable that will store the various type of file formats

27
00:02:40,600 --> 00:02:42,190
that we can save.

28
00:02:42,190 --> 00:02:48,820
So to do that a reference is variable again solve this dialogue

29
00:02:52,240 --> 00:02:55,260
and I'll look for a method that we can attach to that.

30
00:02:55,260 --> 00:03:02,140
So do a dot or a period on the end there and you give you a list of methods you can use and when to

31
00:03:02,140 --> 00:03:03,310
use a filter.

32
00:03:03,310 --> 00:03:08,020
There should be one for a filter Nagle so I'm going to use a filter.

33
00:03:08,460 --> 00:03:15,840
I'm going to set that filter to the various type of for file formats.

34
00:03:15,850 --> 00:03:20,440
I'm going to start with a j peg so we can store J.

35
00:03:20,440 --> 00:03:21,010
Peg

36
00:03:24,870 --> 00:03:30,750
the next one I one to implement upstairs j peg

37
00:03:34,970 --> 00:03:36,370
so let me run through the code.

38
00:03:36,410 --> 00:03:42,630
I have implemented for the Save As event handler.

39
00:03:42,650 --> 00:03:51,120
So when you do the drawing and you click on Save As a to trigger this piece of code.

40
00:03:51,950 --> 00:03:57,050
So I've got a class here called save file dialog and a variable.

41
00:03:57,050 --> 00:04:01,470
This is a variable and this is a new instance of that variable.

42
00:04:01,490 --> 00:04:01,820
Okay.

43
00:04:01,850 --> 00:04:04,800
So it will initialize as a new instance.

44
00:04:04,820 --> 00:04:12,770
So here after declaring this variable I'm using the variable here I've attached a filter.

45
00:04:13,680 --> 00:04:16,850
Okay tells you if you put your mouse over it tells you what it does.

46
00:04:16,880 --> 00:04:24,020
I've attached a filter that will determine what type of files you can save.

47
00:04:24,020 --> 00:04:30,680
You can salvage a peg file JPEG image file or anything with an extension of JP.

48
00:04:31,040 --> 00:04:38,740
You can save a bitmap image file or anything with a dot PMP file format.

49
00:04:39,020 --> 00:04:41,620
And here again I'm using the same variable here.

50
00:04:41,630 --> 00:04:51,380
I've attached a title string here so you can see it will come up as save an image file gives you the

51
00:04:51,380 --> 00:04:53,030
option where you try to save you.

52
00:04:53,090 --> 00:04:59,510
It will come up with this text save an image file as and then again here and reference in the same variable

53
00:04:59,980 --> 00:05:05,760
and which is this here and amusing the sure dialog method.

54
00:05:05,810 --> 00:05:06,770
This is a method.

55
00:05:06,770 --> 00:05:13,360
This method will run runs a common dialog box for a default owner.

56
00:05:13,360 --> 00:05:14,330
That's what it's telling you here.

57
00:05:14,330 --> 00:05:22,510
So this is an inbuilt method I've used here to attach to this variable to show the save as dialog.

58
00:05:22,580 --> 00:05:26,840
So when you're trying to save it you bring up the box that gives you a prompt to save.

59
00:05:26,860 --> 00:05:37,970
As I've also implemented an if statement here saying that if this variable they save as a variable and

60
00:05:37,970 --> 00:05:45,760
the file name is not blank this exclamation means it's not so.

61
00:05:45,820 --> 00:05:54,070
This is a boolean various in that if it is not that if it does what the same you represent a text series

62
00:05:54,610 --> 00:05:56,470
just gives you if you could.

63
00:05:56,560 --> 00:05:59,280
It's kind of like a boolean string operator.

64
00:05:59,580 --> 00:06:08,630
So is checking for a condition and the condition is checking for to see if the farm name is not empty.

65
00:06:08,890 --> 00:06:15,180
Here I'm using the system namespace here and the class file stream.

66
00:06:15,170 --> 00:06:22,620
Class giving it a name of F S and this is what I've passed into the parameter here.

67
00:06:23,290 --> 00:06:30,820
And I've also implemented a switch statement and the expression I'm using to evaluate that switch is

68
00:06:30,930 --> 00:06:32,590
variable.

69
00:06:32,650 --> 00:06:35,330
This filter index.

70
00:06:35,430 --> 00:06:43,180
Yeah so what this will do it will check for different conditions before it execute the code.

71
00:06:43,180 --> 00:06:51,670
So there are two cases inside the switch statement and it will execute based on the condition.

72
00:06:51,670 --> 00:06:58,300
So these are this is case 1 a tool check for the condition and execute this code.

73
00:06:58,300 --> 00:07:05,200
If it's a j peg to the file you're trying to save is a JPEG it will execute this code and the code will

74
00:07:05,200 --> 00:07:06,170
break out there.

75
00:07:06,250 --> 00:07:11,430
Nothing else it will not execute this once it's a JPEG it will end here.

76
00:07:11,590 --> 00:07:16,340
So this break meaning no more execution of the code because it's a pig.

77
00:07:16,360 --> 00:07:24,910
If however the file you're trying to save is a bitmap file a tools it will jump pass this and go to

78
00:07:24,910 --> 00:07:29,960
Case 2 and execute the piece of code and then break the code.

79
00:07:29,960 --> 00:07:34,590
That means break meaning it terminates the code nothing else will run.

80
00:07:34,590 --> 00:07:35,010
All right.

81
00:07:35,020 --> 00:07:40,200
So these are the two cases based on the type of file you are trying to save.

82
00:07:40,360 --> 00:07:42,170
So that is it.

83
00:07:42,190 --> 00:07:45,030
So we should be able to test it now and save.

84
00:07:45,100 --> 00:07:50,240
So let's run the application let's try and do some basic drawing here.

85
00:07:50,290 --> 00:07:59,590
So I just say just random stuff click on the white button click on purple

86
00:08:02,860 --> 00:08:07,900
click on the green click on Blue.

87
00:08:07,900 --> 00:08:10,520
Just try different colors red.

88
00:08:10,590 --> 00:08:12,570
All right let's save the masterpiece.

89
00:08:12,570 --> 00:08:15,550
It will do file save us.

90
00:08:15,550 --> 00:08:23,830
This is maybe the the button we the dialog we executed the code for click save us and it should give

91
00:08:23,830 --> 00:08:24,760
us this window here.

92
00:08:25,780 --> 00:08:35,670
So I just say my Picasso notice is giving me the format of J.

93
00:08:35,710 --> 00:08:43,510
So if I save it as j peg it will execute the first case in the switch statements click save and I can

94
00:08:43,510 --> 00:08:47,100
now terminate that if I open up the app.

95
00:08:48,130 --> 00:08:50,870
So this is the image I've just saved.

96
00:08:50,890 --> 00:08:52,900
If I double click on it and they go.

97
00:08:52,930 --> 00:08:54,340
So that's my Picasso

98
00:08:57,450 --> 00:08:58,160
so that's it.

99
00:08:58,200 --> 00:09:04,450
In this lecture we successfully wrote the code that enabled us to save our image.

100
00:09:04,530 --> 00:09:06,030
Thanks very much.

101
00:09:06,060 --> 00:09:06,710
Bye for now.
