You guys are continuing the development of our current wind farms application and we're know at this
stage what we want to actually start collecting the information from the farm upon submit.
No I want to use this about a minute to explain a very important concept that can save you a lot of
time in your development activity.
And this is renaming your controls so when we're designing this farm we went to the tool box to drug
law that controls and replace them where we wanted we change a few properties one property we did not
change was the name.
So if we click on the text box we would see that it has a name property and every control that you're
going to click on has a name property and the name here is text box one no by default.
It's going to always be counting.
So if this is the first x box it's going to be a text box on the second text box is going to be text
box to the third fourth et cetera et cetera.
That is not ideal when you have a few text boxes because you want to know which text box exactly has
the customer name.
So by leaving them as the default name text box on Text Box 2 et cetera every time you're going to want
to know the information you're going to have to come back over click on the text box look at the name
and say Oh yeah.
That's the one I want.
So I'm going to give you a little technique that's his best practice actually that will help you to
reduce the amount of investigation and you know time you spend trying to find the control you want and
that is simply to change the name.
So I have a simple convention where I use that prefix to take to determine or to the peak rather the
type of control that is being referenced and then I give it a name that is akin to the information that
it's supposed to have.
So let's do the text box so I have the text box here.
That's his gloating customer name.
So my ideal name for this is not Text Box 1 but it would be something like TB which is short for text
box or you could say a t t whatever it is but some prefix that says this is a takes the box.
Right.
So I'm saying TB customer
customer me can't know that this is me naming the objects.
So remember I said that each control is an object.
So by saying TB customer name I not take Suboxone.
This object is no called TB customer name.
The same rules that apply to deeming a variable apply here.
No spaces no special characters all set of the underscore just the simpler the better.
All right.
So no need to have in a long complicated need with 50 characters.
Somebody asked me one time if there was a character limit.
I said there is none but I'm not entirely sure why what he had in mind for a name.
But you know the simpler the better.
So TB cluster My name is saying that this is a text box simple that should be holding the customer name.
And I'm going to repeat that for every other control because then I want to be able to reference them
easily from code.
But let's just start with the TB customer name and then I want to be.
I want that when the person click submit I want to print the contents of the customer need takes box
in another window someone to acknowledge that.
Okay.
CAR has been rented to that person.
So that means my clique needs to work my Submit button needs to do something when it is clicked.
So I would stop Campbell being very deliberate when creating your events and I'm going to show you exactly
what I meant.
So we could.
Car button we go to properties and then you notice that in our proper discipline we have this paper
with our wrench on top it may look you know shady on my display but it may look better on yours but
that paper with that wrench that's the properties we know are the properties section of the pin and
then we have this lightning bolts and if we hover we see events.
So when we hover over our lightning bolts we see the menu switch and then we have a bunch of options
for events.
And once again an event is like our reaction to an action.
Right.
So a click is an action.
What do you want to do when I am clicked.
That is basically what an event is.
So I have the button and I want to determine that something should happen when said button is clicked
so far that I need a method stub so I can click this.
Make sure I am click and then double click in this look editable looking area.
And when I do that it generates that method stub just like it did with the label when we double clicked
it's in our previous video.
All right.
But once again I was very deliberate.
I knew exactly what I was doing.
So long story short the shortest way to make I click event for a button for sure is that just a little
click it then it will generate that event no problem.
But I want you to be very deliberate when you're doing that.
So you know exactly what you're doing.
You're not making any mistakes along the way or reducing the mistakes you make along the way.
So we wanted to click event so no it brings us over to the code file or the code behind.
And then this is take a look at what this click event looks like.
It's a private void and then it has the name off the button but no one on the score click.
Right.
So that's another reason you want to rename your controls because you fired six buttons.
I wouldn't want but one underscore a click button to underscore a click instead.
If I call that this button submit and then I said and then I generate the Click event sorry.
So if I had renamed it's in the properties which I didn't and I won't.
Since we're this far ahead.
I'm just explaining the concept you had I changed the name to submit or something like Beatty and submit.
Right.
And then generated the events then I would have gotten Beatty and submit on the score click.
So whatever the name of the control is on the score.
The type of events.
That's the naming convention that will always be used when generating these method stops.
All right.
And then the it is taking to two parameters object sender and event args e I'm not going to get into
what those mean at least not yet as you go along you see their purpose.
But right now what I want to do is display some form of message to see.
Thank you for submitting your information.
So I have a simple message box in C sharp so I can see a message box dot it is a method called Sure.
So if you're familiar with the console or right line it's very similar.
Console.
Right.
Land rights to the console message box that show shows a message box with a message in it and that message
has to be a string.
Right.
So what is the message you want to display.
You just see.
Thank you for branding.
All right.
So let's just leave it at that.
Thank you for anything for now.
Let's just see how these methods work or this clicking event.
So when I click Start All right.
And then I fill out my form.
So I'm just put a random date US type of car.
It's oriented on the first then it's going back Monday.
And then I click submit.
Then you will see the message box.
Thank you for anything.
All right.
So that's what happened when I clicked then he'd call the phone son.
So that's the event because the phone son is there but notice it didn't fire until the click happened.
All right so that's the core feature of events driven programming.
So no I can inject that takes coming from the textbook.
So I'm going to use interpolation and do a little concatenation here.
So I'm going to put a dollar sign before the string and then inside the string I'm just going to inject.
I want the text from the text box.
What's the name of the text box remember that we renamed the text box to be TV customer names.
So when I want to make reference to that control I just need to make reference the name of the control
TV that customer need.
They'll be that close to my name if I hover over it you see that it is a text box that's it's a class
type.
Right.
But in a room with that these are objects of type whatever control they are.
So this is an object of type text box and it has all of these properties the property that gives me
the data that was entered into the text box would be text.
All right.
So there is that takes property.
It's we didn't fill it all it's because well you don't want takes the B instead of your textbooks at
the start.
But then once I do use I have enter text into the text box.
Then you want to text from it.
So we need to see.
We want to be customer name.
That's our text box control.
Dot the property text.
So this will give us the text that was entered into the text box during runtime.
So let's try that again.
So I want to click start and then I'm going to see B Gil Walters and The Abigail Walter Walters spelling
sorry.
All right.
Abigail Walter Walters and then I click submit and then there we go.
So we have the message box showing thank you.
Thank you printing.
Thank you for pointing.
All right.
So I can just modify all of that anyway.
So thank you for printing such poor English.
I apologize.
Then I can just say call on and the customer name that was entered into the text box art.
So that is it.
So I'm going to put our break point on this line just so we can see exactly what's happening.
So when I click.
Line for me line 20.
Might be a different line for you.
I the name off the method or the line that the method definition starts on kicking in.
This isn't creepy in between the leftmost being and the line the code line numbers and then that little
red dots will appear.
So that's a debug or a breakpoint rather and then I click Start.
So what happens is that this breakpoint is going to get hit under certain circumstances.
So for as long as the program is running the breakpoint isn't being kids who are doing all of these
things the very point isn't being hit until we hit submit and then we see that.
Okay.
That is where it really calls a function.
It pauses in execution.
So once you see that yellow arrow it's pointing to the line that it's no at.
And if we sit down and take some time to assess what's going on here when we're in debug mode we can
actually see what's inside our variables.
So if we hover over a center you'll see that sender is telling us that it was some submit some some
subnets are some control with the text submit sent the call to this event.
Right.
And if you look in the e you see some other stuff.
Once again I'm not going to get too much into what all of those mean but the fact is that visual studio
allows us to pause our code in execution you know go line by line and see something.
So in here you're running into program.
You know that logic arrows or something like that I just want to see exactly where your mistake was.
You can use these breakpoints again a pause and step through I won't go through the step through just
yet but I'm just going to remove the breakpoint so just by clicking back where the red circle was that
turns its on and off.
And then I can just click continue and then it will continue with the execution and then it says thank
you for pointing and whatever and then text was entered into user into the customer name.
So following that principle I want you to stop this video or right.
No.
And then go ahead and rename the controls and then try and produce a message box that print so the contents
of each of these controls and so you would have something like order newer into customer name is this
the date or intent is that the date returned is that and the type of car and that is that.
And that's what I expect to see in your message box.
All right.
So I hope you at least pause the video and attempted what I'm going to walk you through changes that
I just made so I continued and I renamed my controls so I changed my date picker daytime picker to DTA
rented I call so that data and did I choose the DTA entered the 1 4 date returned.
I said DTA returned.
So if you didn't do it and you want to follow along just you know you can follow along just pause as
you need to go along for the combo box I changed it to CB type of car.
So once again I have the prefix for the type of the control and then the name.
So CB full combo box D for daytime TV for a box I mean it's up to you I'm not telling you to use those
prefixes exactly you can choose your own just a humble suggestion that will help you along the way.
All right.
And then I modified my submit button so let's look at some of the code I wrote in the submit and you'll
see some very different code and I'm going to walk you through exactly what's happening here.
So I like that I am able to generate variable and then store the value from the control inside the variable
know that vantage for that for me is that when I have it in a variable I can do anything I want.
So it's easier to manipulate when I puts it in a variable than to be writing if I needed to write the
text five more times after it has been entered in into the text box.
I don't want to be seeing TV that takes TV customer name that takes every time.
So if I put in a nice convenient variable I can use this variable along the way and do any other computation
I want.
So my humble suggestion is that for each control that you're going to be taking data from.
You have a corresponding variable to accept it and then you can manipulate the data through the variable
as you wish.
All right.
So I have string UserName collecting the text for the user name text box I have string dates all it
and then look at what I'm doing here and also the the date time picker is going to be bringing back
the value of type of date time but I intend to print a string to screen so I can't put the time on into
the string just as easily so I have to do all type conversion where I just see the string so I'm getting
the value which would have been whatever is set inside of the text box or the date time speaker.
That's the date and then I'm just seeing Give me the date as a string.
Now there is much more we can do.
What I'm going to keep it simple right.
No I do the same for beats in string date in and then I say D2 returned value and then I say to string
some converting these two data values into strings so that I can print them knowing the fourth line.
I have a different variable type that we have never looked at or at I haven't looked at with you.
And that is called var.
No this is not really a data type.
This is not a data type a tall.
Var is like it is just like an agnostic declaration that we can use on a variable and then this variable
will be relative to whatever is being assigned to it.
So let me just make some space between them.
So notice for every other one I said this is supposed to be a string.
So we know it's a string.
As we look at it we know that these are strings.
When I say var I am seeing var because I am not sure what kind of value would be put into it.
So I can declare a variable as var and then if I signed the number one to this then car type becomes
an integer.
See there.
So I said var but then I said car type is equal to 1.
It is not an integer so it knows that one is an integer so the variable are the the the variable type
is not an integer if I say at one point one which you noisy that Dobler floats and I hover No it's a
double.
So if I send a string then car type is not a string.
All right so the point is that VAR is a very very very very I like.
I actually love using virus so much that it took me a while to remember that I can write the word string
so VAR is very very convenient very flexible you can use it if you wish you will cut down the time of
trying to figure out what data type your variables are your object needs to begin to see var give you
10 name equals and whatever you assign to it it just knows that that is the data type it's working with
that that moment right.
So that's very convenient.
So I just use this opportunity to introduce that to.
So I said var car type is equal to the combo box which I call the CB type of car dot selected item because
I want that when you select the one from the droplets that's the one I'm interested in getting back
and then I have to do a two string because selected item is a type of object.
So then I have to see convert that to string and then it gives me the string value of whatever was selected
and then with all of that done I can no say message box.
So this is the ultimate objective message box.
Sure.
And what I'm going to be showing is I just use my interpolation and read my nice paragraph someone to
say something like customer name.
Hold on.
And then instead of having to write TV custom one named Tex.
I can just see customer name because I stored the value from the text box inside of this variable.
All right.
And then I can do a line break here.
So what I want is each value in its own line.
So to do that in C sharp in a string have to do something like that and box.
Ah so this is the break.
This is so I get that break is almost the cost of a name enter.
Then the next bit of information intense each time you see this it's that can enter key for Assad.
So cluster my name in one line that I break line.
Then I can press enter and it will automatically just adjust the string to allow me to continue typing
so I'm doing this because I don't want to type too much to the right and off the screen.
So I have customer name and then I'm injecting the variable and then I have beat or entered colon and
then I'm going to inject the variable beat out.
All right then I'm going to break again.
So to me at this fast I'm just going to copy this set off the to at the every time break it to the next
line and then they'd returned
colon and then this would be beat in all right.
And then say I didn't write it properly.
So case matters very very much reclined again.
And then the card type all right.
And then we inject the variable which is car type.
All right.
And then.
So the expectation though is that when we fill out our form and that we click Submit we're supposed
to see all this information.
And let me just add one more line which just is thank you for your knees.
All right.
So let's try that.
So I press start.
All right.
So I have customer name test in third day or and it is Saturday.
For one day to be returned is the fourth and a type of cars a lotta.
And then I click submit and then there we go we have customer name the texture of the text box we have
the date printed and the date and time date and time the car type is Lada.
And then the thank you notes ha.
So that's all we go about getting information from our farm and well manipulating it thereafter.
So this manipulation is really just to present it's the manipulation could be to you know do our computation
on the values that are there.
It could be that we submitted to the database whatever it is the fact is.
We know how to get the information.
So later on we look at how we add things like validation and all the features like sending into the
database.