C# How to Create a New Visual Studio Community Project

Little Bear
8 min readFeb 8, 2023

--

This article will show you how to create a Visual Studio Community C# windows form project, step by step. And the introduction about the basic controls, dialogs, and components in the toolbox of visual studio community. It also contains a simple example that will change the title of an application by button click event.

After learning this, you should be able to create your own project and pick up all the necessary components for your application.

Create a Visual Studio C# Windows Form App

The screen shot of vs community create a new project.

After start the Microsoft Visual Studio Community (vs community), it will pop up a sub window ask you about what kind of project you are going to create. Base on the installed modules, it may appear C#, VB, C++, or other programming language. And for each language you might see different type of projects, such as Console App, Class Library, MSTest Test Project, or Windows Form App.

In here, we are focus on C#, so the language type is C# and the application type is Windows Form App.

vs community create a new project and use option C# Windows Form App

After click on Next button, you will see the next configuration about this project.

vs community config the project file location.

VS Community will ask you to give this new project a name, file location, and solution name. If you are new to visual studio, except the project/solution name, try not to modify the file Location and focus on the learning target.

About the relationship of project and solution in visual studio, a project is belong to a solution and a solution can consist of only one project or many projects. For the case of “many projects”, the follow is the example of that situation. One guy write an C# application software using solution “SOL” base on customer’s demand. In this progress of developmen, he needs to write a new library for some purpose. So this new library project will be added into the same solution “SOL”.

Click on Next button to get the following screen.

vs community select the framework.

For the current vs community, the default .NET framework version is .NET 6.0. Try to select the lower .NET version number unless the latest version is surely needed.

Hit Create button.

Windows Form Designer in Visual Studio C#

This is a typical empty c# application designer page and shows a basic windows form. You can drag various other controls and components on it, such as label, textbox, status bar, or menu. This form is what you will see after compile and run the windows form app project.

The Properties of the Windows Form in Visual Studio C#

Use the mouse and right click on the form, then select “Properties”. You will see the Properties of this form as below.

vs community, the properties of the form.

There is an icon shows “A”, “Z”, and an arrow points down, click on it. So, the name of this component is “Form1”, and the property of “BackColor” is “Control”.

The Solution Explorer in Visual Studio C#

The solution explorer of vs community.

Now, check the solution explorer. You will see the Solution name “WinFormsApp2” and the c# project “WinFormsApp2” on it. Under the project, there is a “Form1.cs” on the list. The previous form page is defined in there, include the designer and the source code. Every component and events you add in the form, will appear the corresponding program code in here.

The Toolbox of the Windows Form in Visual Studio C#

Open the toolbox of the windows form.

For open the toolbox, click on View on the menu, and select Toolbox. The toolbox will show up.

The toolbox of vs community project.

Check the toolbox you can see a bunch of groups there. The group “All Windows Forms” will show all the tools in the same time. The other groups will just show part of them base on classification. There are Common Controls, Containers, Menus & Toolbars, Data, Components, Printing, Dialogs, and General. You can also define your owner user control and put in here and this will be discussed in other article.

The Common Controls of Toolbox in Visual Studio C#

The common controls of the toolbox.

For a windows form application, you might remember these common controls. For a button, click on it and will trigger an event such as open a new window, show a calculation result, or update the parameters. For a Label, it can be used to display some text information. For a PictureBox, it can display an image. For a TextBox, the user can input some information there.

The Containers of Toolbox in Visual Studio C#

The containers of the toolbox in vs community.

The container can hold common controls, components, and dialogs on it. If you modify the font and its size of a container, then all the controls or components attached on it will also be changed too.

Some of the typical applications of the Containers:

The GroupBox can be used as a function group. For example, if you design a function for user to save all the parameters just made, then you can use a GroupBox consists of a TextBox, a Label, and a Button. The TextBox is for the file name input, the Label reminds the user that the TextBox is for the file name input, and the Button will trigger an event to save the file.

The TabControl can be used as the container for holding different function sets or parameters in different tabpages. This is useful if user want to find a target item from a bunch of functions or parameters.

The usage example of SplitContainer can be a topic menu and its contents, all the candidate items and the selected items.

The Menus & Toolbars of Toolbox in Visual Studio C#

The menus & toolbars of the toolbox in vs community.

MenuStrip is the menu of a software. You may see File, View, Config, or Print on it. ContextMenuStrip is the pop up panel which shows a menu list when user right click the mouse.

The Data of Toolbox in Visual Studio C#

The data of the toolbox in vs community.

BindingSource can be used to link to a data source, such as MySQL/Excel, then link to a component for display, such as DataGridView.

The Components of Toolbox in Visual Studio C#

The components of the toolbox in vs community.

BackgroundWorker can run a thread in the background and show the result on the UI (user interface/windows form) when the jobs are done. So it can avoid the UI be blocked by some heavy tasks.

ImageList can hold a list of images for a later usage, such as display.

Timer can be used to update the information on the UI thread without pay attention to avoid the errors caused by multi-thread. Just be carefule about the heavy tasks on the Timer will block the UI.

The Printing of Toolbox in Visual Studio C#

The printing of the toolbox in vs community.

The tools for printing job.

The Dialogs of Toolbox in Visual Studio C#

The dialogs of the toolbox in vs community.

OpenFileDialog and SaveFileDialog are commonly used in various softwares, they pop up a dialog to guide the user pick the file for load and save.

A Simple Example of Changing the Title of an Visual Studio C# Application

After the introduction of toolbox, let’s try to make a simple C# project.

The goal the C# application is:

  • Setup a TextBox and a Label for user input a message
  • Setup a Button and the click event to change the title of this application base on the input

Step 1. Setup a TextBox and a Label for input

  1. In Common Controls toolbox, drag a Label and a TextBox on the form “Form1”
  2. Mouse left click on Form1 and modify the “Size” under “Font” Properties of Form1, from 9 to 16
The font size property of Form1 in vs community.
Current Form1 outlook.

3. Modify the “Text” property of label1 to “Title”

4. Modify the “Text” property of textBox1 to “Hello World”

The current outlook of Form1.

Step 2. Setup a Button to Change the title of the application

  1. In Common Controls toolbox, drag a Button on the form “Form1” and select it
The button control in a project of vs community.

2. Double click on the new button1

The click event of button1 of C# project in vs community.

3. Edit the code of button1 click event to write the code to change the title of the application

The click event of button1 of C# project in vs community.

4. Complie and Run this project by click on the solid green triangle

Compile and run the project in vs community.

5. The application will pop up

The simple application of this project in vs community.

6. Click on the button1

The simple application of this project in vs community.

You can notice that the title of the application has been modified to “Hello World” !

--

--

Little Bear

Little Bear, a funny bear with a smile 😄 on his face. A technical writer of Visual Studio C#, and Inspiring Stories. 🚀 https://medium.com/@bdragonpp/subscribe