Diving into Console Applications: Beginner Visual Studio Tutorials
I have delved into object-oriented programming a tad in the past, but I was really intrigued with the idea of being able to create software applications using C#. After researching how to best accomplish this task, I found that the programming language can be integrated with Microsoft Visual Studio. Visual Studio is known as an integrated development environment (IDE). One of the best features of Visual Studio is that it has tools that can be used to test, manage code, and write code. I followed a guide provided by Microsoft to best figure out how to download and install the software.
During one of the steps of installation, you are asked to choose which Workloads you want to install. After some investigation I found that Workloads contain groups of components specific to either a platform or programming language. The components house everything one would need to create an application with your chosen programming language, such as, tools, libraries, and templates. Currently Visual Studio has over 16 Workloads. Seeing as I was interested in creating desktop applications using C#, I installed the .NET desktop development and the universal Windows platform development workloads.
Once install was complete I found a beginner's tutorial that would walk me through creating my first Windows app. I had to simple form where a user would click a button, and an output would be displayed. From the tutorial I was able to figure how to add elements to my app via the design form with the Windows Design Form. I was also able to see where I could input my own C# code in the form. Learning how to work the two features in together can unlock many design options that I have yet to learn how to code for strictly using the little I know of the C# language.
Next I moved onto a tutorial where I would create a picture view applications that made use of buttons, user loaded pictures, pop-up dialog boxes, and more. From this tutorial I learned how to use the TableLayoutPanel from the toolbox, which is GUI framework element that helps to put controls (e.g., labels, buttons, textboxes, etc.,) into a grid layout. This layout control is extremely useful because it allows you drag and drop controls into pre-arranged/pre-sized rows and columns you created. Thus, this eliminates the need to manually size and arrange each control you add to the application.
In the final portion of the tutorial I got into C# code. What I found most interesting about this portion was the intersection between the Windows Form (user application display) UI controls and the C# code. For instance, by double-clicking on a button in the Windows form designer, I was able to create an event handler in the Visual Studio IDE that displayed the C# code for such an action. I was then able to write further code to manipulate the control to do exactly what I needed it to. I assigned "pictureBox1.Image = null;" to the "Clear a picture" button control, so when a user clicks the button the code will execute and remove the photo.
I also needed to code if-else statements for the check-box control I created. While I was already familiar with such statements, the use of the SizeMode property and its values of stretch and normal where new to me. From my understanding the property is used to adjust the size and location of an image on a Windows form. Its value can be set to move a photo to center of a page or change the size of an image to fit in the control. In this app specifically, the property was set to execute under two conditions that were dependent on whether the user had selected the "Stretch" check box or not. When selected the image would stretch to fit/fill the control. However, when left unchecked, the image would invoke its default attributes (i.e. normal) by positioning itself to the upper-left hand side of the control and run the risk of getting clipped if it is larger then the PictureBox provides it.
This basic tutorial has allowed me to become familiar with using Visual Studio to create desktop applications with C#. Having explored the tools available in the ToolBox I am left intrigued by the possibilities this new knowledge will bring me to. Next week I plan to exercise this new found knowledge and, hopefully, expand on what I learned this week by attempting a coding challenge involving another PictureBox control.











Comments
Post a Comment