Getting Started with Visual Studio, C# and Windows Forms

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey how's everybody doing this is my first tutorial on getting started with Visual Studio and c-sharp developing microsoft windows applications using c-sharp in the.net framework so basically we're just going to fire out Visual Studio I'm using Visual Studio 2015 what you're going to want to do is if you've never used Visual Studio you can download it off Microsoft's website and you can set it up for a lot of different types of code basically what I'm gonna do now is just go to noon new project and you can see all the different types of templates and coding that you can use Visual Studio for Android web lots of different types of windows windows a touch screen I mean there's all sorts of different stuff you can do but we're just going to a basic windows form application to get going here so we'll call it getting started with visual with getting started with visual studio or c-sharp because that is it's a programming language that we'll be using basically what Visual Studio does is it fires up with your first form that'll load when the project loads and what you have is your tool strip your menu strip across the top what I usually keep open is my toolbox my data sources properties and my solution explorer there's a lot of other windows you can have open if you go up to view you can check out other windows everybody's different and there's a lot of different ways to code using Visual Studio but basically the gist of it is when you these are all your controls that you can use and out of your toolbox and these are your forms that you can build if you're using if you're building windows forms and over here use your property or properties for whatever control or form that you have clicked on so for instance this is the name of the form and you can change it usually my the form that starts the program when you fire up your your application I call the dashboard of the splash screen sometimes depending on what I'm doing changes them and you tell a lot of the properties our aesthetics some of them aren't but some of them are properties to do a lot of different things but for instance we'll call this the dashboard and they'll change the label on the top of the form and you can change the background colors and a lot of different items if you double click on your form basically what it does is it goes straight to the dashboard form load event or method and what this does is you can type in some statements or some code so that you can make something happen when your form loads you can also click on your form and up here in your properties you can click on all of your events and these are all the different events that can happen when this form is active or you're using this form and you can obviously have to be creative sometimes you know if you have if you want to clear some text boxes when the user clicks on the form you could use the click event there's a lot of different things you can do a million different ways you can color in applications you have to be creative but this was first tutorial I'm just going to show you how to add some basic controls to your form and how to do a couple a couple of common events like a button click event or a click event in general and some simple variables so what we'll do here is we'll throw up a menu strip and that's users typically ohe on a you know windows form a Windows application a lot of times you see the menu strip across the top just like in Visual Studio it's pretty common a lot of times you have file you know open save and like I said you can have whatever you want here what we'll do here is we'll do a couple different tabs we'll do projects and we'll do some tasks it's what a lot of people work on projects in tasks and we'll add a couple other controls maybe we'll add a combo box and a label as you can see just drag these over a text box is pretty common then we'll just throw on lots of check box button we can quickly show you how a lot of these words in a list box we'll start with those every every control has different properties as you can see in your properties panel over here you do want to get into the habit of naming all of your controls so that when you're coding your application you can easily remember what your controls are for setting the properties of them our variables so for our label or we could call it we can leave them as they are now but obviously if you make a bigger application you're going to want to change the names of them so for instance this property right here is the text of that label so you can change it there are some bait the ink you can anchor your controls and what that does is it sets how the controls act when the form is moved around or created or moved around or resized during runtime so for instance if we set the anchor for this this box to be the basically what I'll do is it'll anchor it to the top so this won't move but these will move when the form is resized because they're anchors they're anchored to the right in the bottom side of the form so you can see now that that form changes like that for that listbox changes when we move the form and again these are all items that you want to kind of come up with when you're designing your form figure out how you want your application to work but again every control has different properties so for instance a combo box you want to add items in your collection which basically adds the items that are going to be in the combo box and list box has the same idea you can put items in the collection in later on in some tutorials I will go over how to bind these appliqués are these controls to Microsoft Access databases or sequel databases so you can pull information for your users out of a database instead of just using variables and c-sharp coding and your button you can change the name have your button a lot of times people say well what well I'll show you in a second so if you wanted to debug your program you just click on the debug the start button up here and what that will do is it'll build your applications it's building right now and those and then what it does is it runs it and so right now I can actually type in here or I can also select an item but the problem is is you know what if your user changes the item a lot of people ask you know I don't want them to be able to do that you can see our menu strip up here when we click on them right now nothing happens same with our items or our button you know nothing is going to happen but so by changing the properties of your controls for instance with the combo box you can get your application to work for the way you want it to a lot of these properties you just have to learn for instance the drop down style if changes to a drop-down list now your users won't be able to change the text of your combo and the only be able to select the items that are in your combo box and that was just done by changing the properties of that control so that's how properties work on a lot of the controls I know we ran through it pretty quick as you can see the font in the real I think confusion with a lot of people getting started I know it was a little bit confusing for me when I got going with c-sharp a long time ago was the difference between dragging over a control from the visual studio toolbox which is super easy and I think a lot of people I don't think they take it for granted but they forget all the coding that's done behind the scenes for these controls because if you go to the Microsoft website and you look up you know how do I add a you know open file dialog to my control or to my F form fit well visual or what Microsoft does is they they teach you how to hard code I call hard coding the the control for your form what I did there was I just dragged over the Open File dialog and it Visual Studio generated it for me then I can change the name of it and I can change some of the properties of it and if I want to use that dialogue stay on a click event I could double click on my open menu strip item and then I could I could call the show dialogue method for that dialogue box and what that will do is when you click on that item it will actually show that Open File dialog in that Open File dialog is designed using the visual studio interface and the properties are set right here in our properties dialog or our properties tab and there's our dialog you can see the file name is open the file dialog which is this right here if I wanted to change that I just go over to my properties tab oops just have to see if Familia cams running here I actually use camstudio to do my screen captures I had to pause there for a second my kid just came home anyway so we change the filename and basically what you can see is by changing these properties quickly when we debug the program you can see how fast you can change the properties of different controls this is the filename cover looking for right there so those are some examples I mean what we did here was a click event and again if you click on a control and then you click on the events these are all the different events that can be raised by that control item and you can see that the click event is attached to the this click event right there which if we go back to our code it's just right here and you can actually make your own methods or events if you want to be raised by an event of a control you can have that happen and so that's quickly how you can add different controls different items so what we were talking about before was if you go to the Microsoft website they'll show you how to hard color in items what we did here was this open file dialog as an example we dragged it over from the toolbox and what that did is was it added the control but if we wanted to just hard code a open file dialog box what we would do is we would create the object so base what this is doing is you're typing in the name of the object that you want to create and then you have to give it a name and then you have to instantiate the object which basically creates a space in memory for the item so that it's there it's in your computer it can be run in the application and once it's created then we can now give this new object some properties so you type in the name of it and then you can start giving it or you can run a method off of the object which is the show dialogue method but if we wanted to these are some of the properties that you can give the new object so the filename is what we had changed v4 so what we did is we set the filename for that and then what we'll do is we will show the dialog by calling the show dialog method and so you can tell that you know that is not down here this is called the open our seal file dialog and this one is called the new file dialog box and you can see there we hired coders in the property the name of the file that we're looking for and there it is so that's the difference between typing your own code out for an object or creating an object or dragging an object over control over from the tool box obviously it's a lot faster to drag the file or the control over edit the properties as you'd like them to be edited and then if you have to do anything customized you can do it in your code or another way but there's obviously more ways than one to do these items another quick thing for getting going is your error list and your task list basically if I have a control here and I create double click on that combo box so the selected by default if you double click on the combo box it's the selected index changed event is raised and that's basically if you change the item that you selected in the combo box this event will be raised and just to reiterate if you click on that combo box and you head over to your event there's a lot more events that you can raise but having different things happen in your application but if I then delete this out because hey you know I don't want it anymore and I hit save what's going to happen is the form doesn't know what to do because we created an event but it's and now it's gone so what you're going to want to do is you can go down your air list and you can double click on the error and what it's showing here is that you know this events no longer there anymore so we need to delete it and then we can go back to our form and it'll load so the proper thing to do it was if you want to control their anymore or the if you're just getting rid of the event you have to delete out the event in both your program file and and in your form file but if you don't want to control anymore sometime just easier just to delete the control and then go into your code and delete the code behind it and I think that's pretty much it for just getting going well oh actually we can go over to the solution Explorer and what this does is you're going to end up with a lot of different files as you create a larger application if you want to add items you just right-click on your solution and you can add items say we want to add a folder to keep track of you know more files that we're going to create we can do that if we want to rename our form we can do that and it'll ask us know didn't actually renamed everything for me sometimes it asked you if you rename something if you want to have the application update all the files and usually you do because you want all your files to be updated let's say we want to add another form a common thing to do you want to obviously be able to open up a second form you can add new classes which we can get into later on so we'll call this the projects form and we'll actually add a task form to one a new item windows form task form and so obviously this shows your task form you can keep it open if you want to I'm going to keep out of it for now and then what we want to do is on our projects tab we want to open up a projects form so this is someone confusing part or once me when I got going where we already created a projects form using visual Studios interface by just right-clicking in creating a new form and what it did was it gave us that form if we right-click on that you can go to the view the code or the designer this is what the form is going to look like and if we want to add controls or whatever we want to it it's all going to be added to that form so when we call that form we have to create the object you still have to even though you design the form you still have to instantiate it so that there's a space in memory for that form to be run on your computer and now we can we can just show that form which is what we'll do here and the form is going to come out just the way that we've already designed it or like I showed you before this is the confusing part that I had a hard time with you can add properties right in your code or you can just add your properties to the form through the visual studio designer and so what I'm getting at is that we didn't have to if we wanted to create a new form we didn't have to add the form to the file we could we could have created a new form through just coding it but a lot of times obviously it's easier and faster just to use Visual Studio to help you out with this stuff so now we'll call the show so there's two big ones here for showing a form for show and show dialog the show method will show the form but you'll be able to run other forms at the same time whoops and it wants me to change the name of that and we'll do the same thing for our tax form but we'll use the show dialogue and I'll show you the difference between a show dialogue and a show method and what I was getting it with the properties earlier is if I want to add some items to my tax form so say I want to add a label and a text box also those both subsets those will be added to the form when the form is shown when I run it as you'll see so click on the projects so the difference between the show on the show dialog is I created a project form but I can still run other forms at the same time whoops it does fire back up so you can see in the background you can see visual studio shows you the memory usage as you're using your CPU usage and any other items that you want to see which is handy once you get into some larger applications especially calling large functions or database curries and other items but so the difference between show dialog in the show is I can run two forms at the same time but with the show dialog you're only allowed to run one form at a time it runs as a dialog I can't click on anything else I have to end this dialogue before I can do anything else I want to do this is handy using the show method for large applications where I hate running software other people create where you only have one window open at a time it's just not productive and today's day and age and what we'll also do is we'll quickly show you how to use some of the the variables that we have so you remember we created a collection of items in our combo box item one two and three and this is our label one so on our form around our dashboard you can see this is the load event so these are items if you wanted to have something happen when the form is loaded and this is our menu strip item click this is where it's handy to name your your object so you remember what they went for but so if I if I want to change the selected index of this combo box and I want it to update the label I could type in a statement which would do that so right here we would do label 1 dot and we find that the text property is equal to combo box 1 dot and you could do text or you could do the selected item the selected text or selected item 2 string is what I usually use then you can see here the functionality between using code or running using a statement for the event for this combo box from the selected item has changed see how it only happens when the selected item has changed it raises the event which changes the label to equal this item right here which is handy if say you're trying to you want use it you know you punch in all your information into a database and then you just want to go to select the items quickly and hat you know create a report or a form and then print it out for a client or just for work and so that's the end of this first tutorial what we'll do here is actually my our button here what I can do is add a method here and you guys can shoot me an email if you have questions I'm going to throwing up a whole bunch of c-sharp tutorials on all sorts different things printing the PDFs printing integrating with Microsoft Access Microsoft Word using you know Microsoft Access backends there's a million different applications you can run a lot going on and I guess in my next tutorial maybe I'll show you how to build an application quickly so but if you got any questions you can email me at support at our CL technology comm where you can check me out at our scale technology comm I actually specialize in customized add-on for CAD software Autodesk products and civil engineering architectural engineering on lots of different construction industry add-ons for CAD software but obviously I like doing business solutions and so you have to have any questions shoot me an email thanks for watching
Info
Channel: RCL Technology
Views: 87,382
Rating: 4.8242426 out of 5
Keywords: C#, Visual Studio, Windows Forms, C# Applications, .NET Framework, Visual Studio 2015, RCL Technology, Ryan C Lyford, Ryan Lyford, Custom Business Forms, Software Applications
Id: 2fU5ikU4Sys
Channel Id: undefined
Length: 26min 3sec (1563 seconds)
Published: Sat Feb 18 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.