Hello and welcome.
This lecture is probably the most important part of the project because it could well we're right we'll
be responsible for the pic show movement across the screen for this screen saver.
While there are several task we are going to perform in this to make the two to make the drawing and
movement of the pictures across the screen possible.
So we're going to break it into several bits and pieces in task.
The first task we are going to make the window update frequently.
The second task is to want.
We want every time that the windows sub dated.
We want a loop that will loop over all the Brit pick in his list.
All right.
So there will be a loop.
We'll try to implement a loop that will look through all the brick pick in the list.
Also for each of the Brit pick we wanted to move to the left by two pixels.
So we want to implement that for also if the Brit pick the position of the new pick.
If the position is slightly off the screen we want to wrap it to the other side of the screen so that
it keeps on moving.
So that also we want to implement.
So these are these are the task we are hoping to implement to achieve the objective of drawing and making
the pitches move across the screen in a way we've already kind of achieved the first option in that
we have added a timer so just that we need to go back into the timer maybe enable the timer.
So let's go to the click on the form design view and click on the timer at the bottom here and let's
click on the properties for the timer and the end the timer at the moment by default is set to force.
So what we're gonna do We're gonna send it to true.
So it will kick in as soon as the application is loaded.
At the moment we've got an interval of a hundred.
What this means is that this will be the interval that the screen will refresh every 100 milli seconds.
So for example if I said this to say 40 milliseconds what that means is that it will trigger every 40
milliseconds we should give us a a refresh rate of 25 screens.
So we have about twenty five screen updates per second.
So if you want if you want your screen to keep refreshing you know that quick then you can set the interval
to that level just to let you know one minute is equivalent to 60 seconds milliseconds and two minute
it will give you a hundred and twenty milliseconds so if you want the screen to refresh every 1 minute
then you can set it to sixty thousand milliseconds.
If you wanted to refresh every two minutes you can set it to a hundred and twenty merely seconds.
It's up to you.
For me I'm going to you see the difference.
We'll do our live at a forty four now but we'll change it later.
So this 40 will give us about twenty five screen updates.
Second that might be a bit too much but we'll play around with that figure later.
We also need to add a line of code for our timer so click on the event the timeout only has one event
which is a tick so double click on it.
And here we are going to add just one line of code here.
It's going to be a refresh method.
There is a method called refresh Naga.
So we're just gonna add that and that will enable that the screen refreshes based on the proper the
interval will set.
Just saved that.
So what we going to try and achieve next.
We want the window to redraw itself.
All right.
So are we going to implement this through the movement and the drawing.
So what we're going to do going to go there is an event called paint event.
This is what we're going to use to achieve that.
So according to the form design and click on y you will form selected.
Make sure you've got the events section and if you scroll down this should be a property called Paint.
Okay.
Think is right there.
So let's have a look all right.
So here we've got the property here.
Cord paint.
So this is what is going to be used to draw and responsible for the movement on the screen as well.
So let's double click on the paint event to generate a stub event and also double click.
So this is our paint event.
So in between the curly braces is where we'll write some code.
So added some code here in blue.
So this is the code added inclusive of that.
OK.
All right.
So here that we have attached a for each for each loop that will look through this here.
So this class and this class as well in this.
So basically it will loop through that and grab that inside this picture.
So here are a bunch of variables.
So this here is what we'll do the drawing of the images.
Position them on the x axis and on the y axis.
OK.
So this will do the drawing and positioning.
Also I have attached an if statement here.
What this will do to basically what it's saying that if the object moves off the left edge of the screen
move it back to the right H.
That's what this piece of code is say.
What we have done here we have.
We've overridden the default behavior of the of the window.
So the normal drawing behavior on Windows is to have every control painted paint itself.
Okay.
So Windows tells your window to draw itself.
So it does.
But what we're doing here we've overwritten that default behavior.
We don't want the windows to draw itself and we don't want to try to draw any child control either because
that's obviously a big waste of resources.
So instead what we've done we use the paint event and do the drawing ourself.
The result of this is that we essentially have a nice blank canvas to draw.
Okay.
Hands is handed over to controlled by this paint.
This event here.
This is what controls the activity of the canvas at the moment.
It's got a black background which will set which was set when the form was generated with the project
initially so save all your code anywhere you find yellow strips it means your code has not been saved.
Look save make sure there are no arrows always click on this.
That's a tab here that says Error list always click on that if there's any arrows in your code it will
tell you if you've got no arrows.
That means you're doing great.
So save your code.
And in our next lecture we'll test what we have done.
Thanks for watching.
By for at.