In this lecture we are going to add some code that will enable drawing so going to the form designer
which is this one.
Select.
Make sure you've got the picture box selected.
You can tell because it will show the name in the property box.
Make sure you've got this event selected and we are going to look for a property that's called mouse
move.
So let's see if we can find one.
This should be one for a mouse move.
Okay.
So this is our mouse move event so let's double click on it and that will give us.
It also generates the method for that is the event handler for the mouse move.
So we're gonna write some code here that will respond to the mouse movement.
So this method will be run when the mouse enters the picture box element.
So anytime the mouse enters the picture box element this code will be activated to save time.
I am going to write the code and I'll explain what the code that the first and I want to do is implement
and if statement so we do.
If and then we pass it the variable growing parcel into the if statement when you write in an if statement
you need to specify where the code will execute.
So you do that you specify to curly braces.
So I'm just going to put a mouse in between and press enter.
So in between the calibrate this is where I'll specify the code.
So I'm typing graphics intelligence already picks out up and I give it an emoji.
I'll make you a lowercase G and I'll set that to equals to
graphics.
There's a method attached to that.
So if you hit press dot on your keyboard the intelligence will give you all the methods you can use
with these graphics.
So I will.
There is a method called from image.
We use that an every method should have a parent.
This is inside the parentheses.
I will pass it the BNP which is a variable I created for the bitmap opposite that valley.
OK.
Next I'm going to reference that variable
dot.
And I'm going to attach a method draw a clips.
So I'm going to pick this method and I'm going to pass it inside the parentheses.
I'm going to posit some values going to pass it the pen.
That's the pen variable.
We've already declared this before.
And then from values
e dot X I use that
represent the x axis then e the e represents the eclipse e dot y for the y axis
and then the position in 3
and 1 and the semicolon to end that.
Finally our reference of picture books the picture box
our a method to that he'd be an image
okay not the image I'll just attach the image the actual image I said that image to equals to the BNP
bitmap variable.
OK I'm happy with that.
I've got some yellow strips so I'll save my code
the next thing we need to do before we can draw.
We need to activate the pen colours so we going to do that using different methods for each of the pens.
So if you go back into the form designer notice I've created we've created a few together.
I also added the black as well so you can add many colours as you like.
If you want to add white whereby you just add whatever colours you need to add.
So I've got red.
Blue green purple lime black and white.
So to activate the pen let's start with the red.
So I'll double click double click on that and that should open up the code view for that.
So that generates the event for that pen.
So we're gonna write the code for that.
So all we need to do because we've got a pen variable.
So we access in the pen variable which is p dot colour.
Okay.
And then we say equals two colour
dot read.
That's basically what we'll do for that one and you do the same for all the colors.
So you go back into the design view.
We've done the red.
We double click on the blue.
We do the same.
If you want to make things easy just copy
copy that come here paste and just change that to blue.
And do the same for the rest of the colors.
We should now be able to do some basic drawing using our mouse.
So let's check that out.
So let's run the application would go start.
So this is the application.
So let's try and draw using some of the pen.
This is this try.
This is a red pen.
Let's try the lime
Oh.
Good luck Picasso.
Now let's try the white
tribe purple
a go.
Mount Picasso drawing.
So we are able to draw on the peach box now via the BNP variable.
We older than we can do now we can't save the moment.
The save option has not been activated.
So in the next lecture I'm gonna write some code that we can use to activate saving of our drawing.
So that's it for this lecture.
Thanks so much for watching.
Take care and bye for now.