In this lecture we are going to add code that will allow us to save our droid.
So click on the design view and in the file here.
File option here.
I'm just gonna change this option.
I'm going to just I'm going to activate only one of them.
The Save balance leave the other one so you can also if you want to create more many options you can
and then just implement the code the same way.
So I'm just gonna double click on this to give me the Skeletor code.
So this is the event the method that will respond to when the button the save button is clicked.
What we need to do also we need to add is save file dialog so click on the tool box and on the dialogues.
That's an option for self file dialog.
So just double click on that and that should be there.
So this is the save file dialog.
So we're going to incorporate that into our code so that when the files save us option is pressed it
will reference this dialog.
So let me pop back into the code.
So this is the code here.
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
file.
So I'm going to create a will references save file dialogue.
We just added on and set that to a quote set a new instance of that variable to do that type in new
and then save
type save file dialog.
So we're setting it to a course to do that.
So this will create a new instance of that.
The next thing I want to do want to create a variable that will store the various type of file formats
that we can save.
So to do that a reference is variable again solve this dialogue
and I'll look for a method that we can attach to that.
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
use a filter.
There should be one for a filter Nagle so I'm going to use a filter.
I'm going to set that filter to the various type of for file formats.
I'm going to start with a j peg so we can store J.
Peg
the next one I one to implement upstairs j peg
so let me run through the code.
I have implemented for the Save As event handler.
So when you do the drawing and you click on Save As a to trigger this piece of code.
So I've got a class here called save file dialog and a variable.
This is a variable and this is a new instance of that variable.
Okay.
So it will initialize as a new instance.
So here after declaring this variable I'm using the variable here I've attached a filter.
Okay tells you if you put your mouse over it tells you what it does.
I've attached a filter that will determine what type of files you can save.
You can salvage a peg file JPEG image file or anything with an extension of JP.
You can save a bitmap image file or anything with a dot PMP file format.
And here again I'm using the same variable here.
I've attached a title string here so you can see it will come up as save an image file gives you the
option where you try to save you.
It will come up with this text save an image file as and then again here and reference in the same variable
and which is this here and amusing the sure dialog method.
This is a method.
This method will run runs a common dialog box for a default owner.
That's what it's telling you here.
So this is an inbuilt method I've used here to attach to this variable to show the save as dialog.
So when you're trying to save it you bring up the box that gives you a prompt to save.
As I've also implemented an if statement here saying that if this variable they save as a variable and
the file name is not blank this exclamation means it's not so.
This is a boolean various in that if it is not that if it does what the same you represent a text series
just gives you if you could.
It's kind of like a boolean string operator.
So is checking for a condition and the condition is checking for to see if the farm name is not empty.
Here I'm using the system namespace here and the class file stream.
Class giving it a name of F S and this is what I've passed into the parameter here.
And I've also implemented a switch statement and the expression I'm using to evaluate that switch is
variable.
This filter index.
Yeah so what this will do it will check for different conditions before it execute the code.
So there are two cases inside the switch statement and it will execute based on the condition.
So these are this is case 1 a tool check for the condition and execute this code.
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
break out there.
Nothing else it will not execute this once it's a JPEG it will end here.
So this break meaning no more execution of the code because it's a pig.
If however the file you're trying to save is a bitmap file a tools it will jump pass this and go to
Case 2 and execute the piece of code and then break the code.
That means break meaning it terminates the code nothing else will run.
All right.
So these are the two cases based on the type of file you are trying to save.
So that is it.
So we should be able to test it now and save.
So let's run the application let's try and do some basic drawing here.
So I just say just random stuff click on the white button click on purple
click on the green click on Blue.
Just try different colors red.
All right let's save the masterpiece.
It will do file save us.
This is maybe the the button we the dialog we executed the code for click save us and it should give
us this window here.
So I just say my Picasso notice is giving me the format of J.
So if I save it as j peg it will execute the first case in the switch statements click save and I can
now terminate that if I open up the app.
So this is the image I've just saved.
If I double click on it and they go.
So that's my Picasso
so that's it.
In this lecture we successfully wrote the code that enabled us to save our image.
Thanks very much.
Bye for now.