1
00:00:00,960 --> 00:00:06,180
In this video we're going to be looking at designing additional forms in our current application.

2
00:00:06,220 --> 00:00:11,070
Now the reality of the situation is that we're writing an application for our car into a business.

3
00:00:11,070 --> 00:00:17,460
So far we have one form and then we just bring it up quickly and this form is really just collecting

4
00:00:17,550 --> 00:00:23,150
data that goes towards creating our rental record over I'm sure if you sit down and think about it there's

5
00:00:23,190 --> 00:00:30,000
much more to a car into a business than just you know logging the fact that somebody the name the cost

6
00:00:30,030 --> 00:00:34,740
the day is returned and rented that type of car and clicking So I mean there's more to the business

7
00:00:34,740 --> 00:00:37,230
than that there are other things that need to get done.

8
00:00:37,230 --> 00:00:43,350
No the problem is that you don't want to try and do everything on one form because this is one form

9
00:00:43,680 --> 00:00:47,790
we are using this one form to call it our car into the record.

10
00:00:47,850 --> 00:00:56,580
So windfarms allows us to build multiple forms on each form can have its own functionality and pretty

11
00:00:56,580 --> 00:01:02,770
much they're all autonomous meaning they're all able to act on their own so in this video we're just

12
00:01:02,770 --> 00:01:09,250
going to explore what goes into creating our brand new form and how we would go about launching it from

13
00:01:09,250 --> 00:01:09,970
another form.

14
00:01:10,660 --> 00:01:15,470
So back in our project we're going to right click on our project file in our solution explorer.

15
00:01:15,470 --> 00:01:19,360
Now remember we have the solution and then we have this project right.

16
00:01:19,360 --> 00:01:25,600
So I'm right click on the project and then I'm going to click add and then I can see a new item Mark

17
00:01:25,600 --> 00:01:30,910
and see a form either way I'm going to get the same dialog box but ultimately I'm going for to farm

18
00:01:30,910 --> 00:01:37,070
someone to start off with new item and then in new item I can look for a form.

19
00:01:37,070 --> 00:01:42,170
But then I can go to the subcategories to the left and see Windows Forms and then what I'm going to

20
00:01:42,170 --> 00:01:46,020
do is select the form templates which is a blank.

21
00:01:46,020 --> 00:01:51,530
Windows forms and forms form rides it so seeing it gets a blank form a blank template.

22
00:01:51,590 --> 00:01:53,530
It's also asking for a name.

23
00:01:53,570 --> 00:01:59,360
So our very first form that we would have started the project with what's called form one that doesn't

24
00:01:59,360 --> 00:02:02,060
really tell me what's going to be on that form does it.

25
00:02:02,060 --> 00:02:08,540
So if I have up to 10 different forms doing 10 different things I do on form one form to form three

26
00:02:08,540 --> 00:02:12,800
I treat naming my forms the same way I treats naming my controls.

27
00:02:12,800 --> 00:02:18,080
So I'm going to build this new form and I'm going to call it its mean window and that's when I explain

28
00:02:18,080 --> 00:02:24,500
why I'm calling it mean window because I'm actually going to be using this new form for something very

29
00:02:24,500 --> 00:02:25,490
special.

30
00:02:25,580 --> 00:02:31,610
So we call it mean window and then we click add and then a low visual studio to create that new form

31
00:02:31,640 --> 00:02:34,000
and give us this brand new canvas.

32
00:02:34,250 --> 00:02:40,500
It looks just like all form one look before we started dragging over new controls and such.

33
00:02:40,530 --> 00:02:40,990
Right.

34
00:02:41,000 --> 00:02:46,070
No the fact that we named it I mean we know it comes deep by default it's with the word meaning to open

35
00:02:46,070 --> 00:02:47,070
the title bar.

36
00:02:47,180 --> 00:02:52,730
You'll also notice that the new file is called mean window and every other file associated with it is

37
00:02:52,730 --> 00:02:55,300
also called mean window.

38
00:02:55,310 --> 00:03:01,790
Now I'm just going to add a quick label to it so I'm just going to go back to my form one design and

39
00:03:01,790 --> 00:03:03,320
I'm just going to copy this label.

40
00:03:03,320 --> 00:03:09,110
I'm just bored in this label putting it on the main window and then I wanted to change the takes that's

41
00:03:09,110 --> 00:03:15,350
in it so I just click it go to properties and then I'm just going to change it takes to see me in windows

42
00:03:15,350 --> 00:03:18,260
so that when it launches I know exactly where I am.

43
00:03:18,740 --> 00:03:20,500
So main window.

44
00:03:20,510 --> 00:03:22,880
Sorry main window.

45
00:03:22,940 --> 00:03:23,930
There we go.

46
00:03:23,930 --> 00:03:31,000
And also I don't want mean window to just be printed like that's in Camilla case in the in the title

47
00:03:31,020 --> 00:03:37,580
bar maybe I want something else I'm just going to click the form itself right click go to properties

48
00:03:38,030 --> 00:03:43,750
and then I'm going to change a text that is being displayed up there so I'm just going to see mean space

49
00:03:43,760 --> 00:03:48,400
window press enter and then that looks a bit better on the eyes right now.

50
00:03:48,410 --> 00:03:50,600
Let's see how all of this mean window look.

51
00:03:50,590 --> 00:03:55,240
So when I click start it is still going to launch form one.

52
00:03:55,280 --> 00:04:00,800
No this is form one we've been working with form one No I have a new form and I would like to see this

53
00:04:00,800 --> 00:04:07,610
new form on the window however I don't necessarily know haul it to get to that form so I need to put

54
00:04:07,610 --> 00:04:11,420
something in place that allows me to launch this form when I need it.

55
00:04:11,420 --> 00:04:12,070
Right.

56
00:04:12,110 --> 00:04:19,100
So copying a lot of debug mode just clicking stop what I'm going to do on Form One is bringing over

57
00:04:19,150 --> 00:04:26,720
another button so I'm going to show you how you can go about launching another form from what from one

58
00:04:26,720 --> 00:04:28,600
form launching another form.

59
00:04:28,610 --> 00:04:32,420
So we have form one it's always going to come up with form one by default.

60
00:04:32,570 --> 00:04:38,300
But I want that when I click this button I see another form and in this case I have main window as my

61
00:04:38,300 --> 00:04:41,000
next form or my next window.

62
00:04:41,000 --> 00:04:42,670
That can be displayed right.

63
00:04:42,680 --> 00:04:49,440
So I'm just going to go to tool box quickly go to my controls get a button and I'm just putting a random

64
00:04:49,460 --> 00:04:50,450
button there.

65
00:04:50,510 --> 00:04:51,740
Nothing spectacular.

66
00:04:51,740 --> 00:04:53,480
This is just purely experimental.

67
00:04:53,510 --> 00:05:00,020
It's only temporary but I just wanted to get the point across that you can launch a window from another

68
00:05:00,020 --> 00:05:09,300
window so I'm just going to change one or two properties on this button and I want to see a launch mean

69
00:05:09,300 --> 00:05:11,640
window launch mean window.

70
00:05:11,640 --> 00:05:13,610
That's the text in this button.

71
00:05:13,620 --> 00:05:13,890
All right.

72
00:05:13,890 --> 00:05:18,240
So this button is simply supposed to launch the main window right.

73
00:05:18,270 --> 00:05:19,070
No.

74
00:05:19,080 --> 00:05:20,730
It would have to do that on click.

75
00:05:20,760 --> 00:05:26,640
So that means if I'm going to expect the button to do something when it is clicked then I need a click

76
00:05:26,640 --> 00:05:27,050
event.

77
00:05:27,060 --> 00:05:27,360
Right.

78
00:05:27,360 --> 00:05:30,560
So if you finish that sentence just no kudos to you.

79
00:05:30,570 --> 00:05:36,810
So I right click on my button and go back to properties click the lightning bolt and double click in

80
00:05:36,810 --> 00:05:37,710
the click area.

81
00:05:37,740 --> 00:05:42,230
So there are two ways though you can just double click the button that will automatically generates

82
00:05:42,230 --> 00:05:47,670
a click event or you could do all of what I just did by going to properties getting the lightning bolt

83
00:05:47,670 --> 00:05:49,980
and then creating the Click event.

84
00:05:49,980 --> 00:05:52,990
As I said before always try to be very deliberate.

85
00:05:53,060 --> 00:05:53,800
All right.

86
00:05:53,880 --> 00:06:01,560
No I have my button I noticed that button one click here and then I have button on underscore click

87
00:06:01,560 --> 00:06:02,550
on the square one.

88
00:06:02,550 --> 00:06:04,940
So that's where the conflicting names come in.

89
00:06:04,940 --> 00:06:11,610
Because I didn't rename this button and this button is also a button one I know it's two buttons with

90
00:06:11,610 --> 00:06:14,010
similar names with similar click events.

91
00:06:14,000 --> 00:06:18,240
So once again it is best if you rename your controls.

92
00:06:18,240 --> 00:06:18,690
All right.

93
00:06:19,200 --> 00:06:26,970
So I have the button click event for my new button and then I'm just going to write two lines of code

94
00:06:26,970 --> 00:06:34,290
that are going to tell me or tell the button that when you are clicked launch this new window or launch

95
00:06:34,320 --> 00:06:35,490
this new form.

96
00:06:35,490 --> 00:06:36,130
Right.

97
00:06:36,210 --> 00:06:42,360
So I'm going to see a main window so remember that everything in C sharp is a class.

98
00:06:42,390 --> 00:06:44,130
So form one is a class.

99
00:06:44,130 --> 00:06:50,930
If we look at it form one is a class that is inheriting from a base class called farm right.

100
00:06:50,940 --> 00:06:57,090
If I go into mean window it also has its own code files so I can right click me in windows go to view

101
00:06:57,090 --> 00:07:01,240
code and then I'm going to see that main window is also a class of itself.

102
00:07:01,240 --> 00:07:04,770
It's called mean window because that's what we call the file.

103
00:07:05,130 --> 00:07:09,040
And it is also inheriting from the base class form.

104
00:07:09,070 --> 00:07:09,720
All right.

105
00:07:09,750 --> 00:07:17,260
So what I need to do to launch an instance of I mean window is to declare an object of type.

106
00:07:17,260 --> 00:07:18,060
Mean window.

107
00:07:18,240 --> 00:07:23,370
So this is me declaring the object and initializing it's a new mean window.

108
00:07:23,370 --> 00:07:23,610
Right.

109
00:07:23,610 --> 00:07:31,560
So remember in C sharp this is so we initialize an object of a class and then I am going to call a function

110
00:07:31,590 --> 00:07:39,930
inside this object called Show so similar to how we show our message boxes are always said Mrs. box

111
00:07:40,160 --> 00:07:41,690
not sure.

112
00:07:41,730 --> 00:07:42,060
Right.

113
00:07:42,060 --> 00:07:45,070
And then that's what pops up the message box of the screen.

114
00:07:45,090 --> 00:07:51,720
Well all I'm saying here is that I want an instance of mean window and then I want to show this window

115
00:07:51,720 --> 00:07:59,370
once it's created and then we discuss using VARs I could just say a var there instead of seeing mean

116
00:07:59,370 --> 00:08:00,050
window.

117
00:08:00,120 --> 00:08:02,220
The object is equal to right.

118
00:08:02,220 --> 00:08:05,980
So you have the two ways you can write it whichever one you feel more comfortable with.

119
00:08:06,090 --> 00:08:07,200
That's fine.

120
00:08:07,200 --> 00:08:14,150
So no the expectation is that when I click this new button this experimental button in this car into

121
00:08:14,150 --> 00:08:22,060
a system window it will launch window for the mean window or launch of the main window form.

122
00:08:22,080 --> 00:08:23,160
So let's try.

123
00:08:23,160 --> 00:08:24,870
So let's start.

124
00:08:24,870 --> 00:08:25,200
All right.

125
00:08:25,200 --> 00:08:32,220
So I have my car in so form up and then I click launch main window and there we go.

126
00:08:32,250 --> 00:08:32,580
All right.

127
00:08:32,610 --> 00:08:39,870
So when I click launch main window it does appear it just a prism and other monitor noticed that each

128
00:08:39,870 --> 00:08:47,520
time I click it is going to pop up this mean window so you can bake in some intelligence at some point

129
00:08:47,520 --> 00:08:53,090
to see if any instance of it is already open then don't open anymore.

130
00:08:53,370 --> 00:08:58,980
But for now we see that we can launch another window anytime we want.

131
00:08:58,980 --> 00:09:06,810
Once we have the proper code in place now that's pretty much it for how we go about launching an additional

132
00:09:06,810 --> 00:09:09,130
form from an existing form.

133
00:09:09,200 --> 00:09:14,470
So most since we close all the windows our agendas press stop the exit debug mode altogether I'm going

134
00:09:14,500 --> 00:09:20,640
to do one more thing in keeping with the best practices that I'm trying to promote in my videos so far

135
00:09:20,970 --> 00:09:27,990
and that is to rename form one from just form one that's Yes because yes it was the first form yes it

136
00:09:27,990 --> 00:09:29,460
was the first thing that was there.

137
00:09:29,460 --> 00:09:31,310
So by default it's form 1.

138
00:09:31,440 --> 00:09:36,660
However when we start building in other forms you don't want to have to look at the systems and explore

139
00:09:36,660 --> 00:09:42,960
and guess that form one is the car into a window the same way we can just look at this and deduce that

140
00:09:42,960 --> 00:09:48,540
mean we know represents a mean window isn't saying we should we should be able to look at the file name

141
00:09:48,540 --> 00:09:53,060
for the car and I know that it is the car into the record window.

142
00:09:53,130 --> 00:09:59,830
So I'm going to rename this form and by renaming this form visual studio is going to allow me to change

143
00:09:59,840 --> 00:10:05,840
out every reference to this farm one class through all of my solution.

144
00:10:05,850 --> 00:10:15,300
So the new name name I can read the file and see read name and then I'm going to call it for record

145
00:10:15,820 --> 00:10:17,980
or let's be more specific.

146
00:10:18,030 --> 00:10:20,760
I'd bring into a record right.

147
00:10:21,120 --> 00:10:28,860
So remember that this window is all about allowing us to insert our entire record so I'd entire record.

148
00:10:28,860 --> 00:10:34,050
Press enter then visual studio is asking me or telling me I'm renaming a file.

149
00:10:34,100 --> 00:10:41,370
No it's asking me would I like to rename all references to form one in this entire file and I'm going

150
00:10:41,370 --> 00:10:43,590
to say yes I do want to do that.

151
00:10:43,650 --> 00:10:47,670
And notice how a visual studio does reflect does all the references for me.

152
00:10:47,820 --> 00:10:54,620
So that when I build control shift and b there are no arrows in my code.

153
00:10:54,660 --> 00:11:01,320
Also the bigger advantage is that when I look in my solution Explorer I can directly or immediately

154
00:11:01,320 --> 00:11:04,850
detect all the forms and what they are for.

155
00:11:04,920 --> 00:11:05,250
All right.

156
00:11:05,580 --> 00:11:11,910
So the last thing that I'm going to do is look in my program not see us file no in our program not see

157
00:11:11,910 --> 00:11:17,090
us file we have all the code that runs as at the time the program is started.

158
00:11:17,100 --> 00:11:22,970
So when I click start what really happens is that visual studio or what the engine looks still programmed

159
00:11:23,060 --> 00:11:28,290
us this file which executes this main function so if you were doing the console applications and you

160
00:11:28,290 --> 00:11:32,750
would be familiar with the fact that there is a main function at all times.

161
00:11:32,850 --> 00:11:33,110
Right.

162
00:11:33,480 --> 00:11:39,280
And then what it does is initialize some visuals as some takes rendering stuff.

163
00:11:39,630 --> 00:11:43,980
I don't know I'm not going to sit there and teach all these two lines do I would just advise you that

164
00:11:43,980 --> 00:11:46,920
if you're going to move them be sure you know what you're doing.

165
00:11:46,920 --> 00:11:48,850
Otherwise you can leave them alone.

166
00:11:48,900 --> 00:11:56,430
But the one that you can modify is application run where it is running and starting a new instance of

167
00:11:56,520 --> 00:12:01,020
well we just change the name from form one to add our entire records.

168
00:12:01,050 --> 00:12:04,970
So what happens is that when you click Start it does this line.

169
00:12:04,980 --> 00:12:09,510
Does this line and then it runs a new window of order into our record.

170
00:12:09,510 --> 00:12:12,600
Which is why that's the first form that comes up.

171
00:12:12,600 --> 00:12:19,620
So now that we have a main window form that we want to make the landing window for our entire application

172
00:12:19,950 --> 00:12:25,490
we can change this from our entire record to mean window.

173
00:12:25,600 --> 00:12:31,140
Now what's going to happen is that when the program runs it's going to launch the mean window so let's

174
00:12:31,140 --> 00:12:31,590
try that.

175
00:12:31,590 --> 00:12:36,810
So I click starts and what comes up first is the mean window.

176
00:12:36,810 --> 00:12:37,200
All right.

177
00:12:37,530 --> 00:12:44,820
So no the next steps that we have is to transform our entire application into what we call a multi document

178
00:12:44,850 --> 00:12:52,620
interface or an MDI application where our main window with the host menu strip that's allows us to go

179
00:12:52,620 --> 00:12:58,290
between all the features and the respective forms that will be needed to support a functionality for

180
00:12:58,290 --> 00:12:59,670
this application.

181
00:12:59,670 --> 00:13:04,050
Other functionality would include maybe like an archive of all our entire records.

182
00:13:04,060 --> 00:13:04,430
All right.

183
00:13:04,510 --> 00:13:08,180
We're only adding but we don't view them on lists we go to the database.

184
00:13:08,190 --> 00:13:10,230
You don't want to send people to a database.

185
00:13:10,260 --> 00:13:13,020
You want people to be able to view them in the application.

186
00:13:13,340 --> 00:13:16,500
Likewise we need to be able to manage the list of cars.

187
00:13:16,500 --> 00:13:23,060
And there are other things that we maybe want to do in our car into application that we cannot do right

188
00:13:23,060 --> 00:13:23,340
now.

189
00:13:23,340 --> 00:13:29,460
So our main we know will now be the landing window or the first window that launches to show us all

190
00:13:29,460 --> 00:13:31,620
of four options thereafter.

191
00:13:31,620 --> 00:13:36,960
And then by clicking each option we would launch the respective form for that feature.
