Create Your First C# Windows Forms Application using Visual Studio
Summary
TLDRThis video tutorial guides viewers on creating a Windows Form application using C# in Visual Studio. It begins with creating a new project, selecting the appropriate template, and naming the project. The video then demonstrates how to use the designer to customize the form's appearance, add components like buttons and labels, and adjust their properties. The tutorial concludes with a simple coding example that shows how to display user input from a text box in a message box when a button is clicked, providing a basic foundation for Windows Form application development.
Takeaways
- 💻 Start by opening Visual Studio and creating a new Windows Form application project in C# for the desktop platform.
- 🔍 You can find the Windows Form application template by searching or selecting it from the list under C# and Desktop.
- 📝 Name your project carefully, avoiding spaces for better compatibility with file systems and tools.
- 🎯 Choose the latest .NET version available, such as .NET 6.0, to ensure you're using up-to-date features and optimizations.
- 🖼️ The designer view allows you to visually manipulate the form's layout and properties, including resizing and setting titles.
- 🔧 Use the toolbox to drag and drop UI components like buttons, labels, and text boxes onto your form.
- 📑 The properties window is key for adjusting the appearance and behavior of components, such as changing text, font size, and anchoring.
- 🔄 Anchoring components ensures they resize or move appropriately when the form's size changes, maintaining a responsive layout.
- 💬 Write event handlers for components, like a button click, to define what happens when an action is performed, such as displaying a message box.
- ✅ After coding, save your work and run the application to see the results, ensuring that the UI behaves as expected and that your code executes correctly.
Q & A
What is the main topic of the video?
-The main topic of the video is creating a Windows Form application using C# in Visual Studio.
How does one start creating a new Windows Form application in Visual Studio?
-To start creating a new Windows Form application, one should open Visual Studio, click on 'Create a new project', and then select 'Windows Form Application' under C# and Desktop platform.
What are the project type options available for Windows Forms in the video?
-In the video, the project type options available for Windows Forms are 'Windows Forms App (.NET Core)' and 'Windows Forms App (.NET Framework)'.
What is the significance of not using spaces in the project name as mentioned in the video?
-Not using spaces in the project name is significant because it avoids potential issues with file paths and command-line operations related to the project.
How can one access the designer view for the form in a Windows Form application?
-To access the designer view for the form, one can double-click on the 'Form1.cs' file in the Solution Explorer, or expand the 'Form1.cs' node and double-click on 'Form1.Designer.cs'.
What is the default name given to the first form in a newly created Windows Forms application?
-The default name given to the first form in a newly created Windows Forms application is 'Form1'.
How can one change the title of the form window in the designer?
-To change the title of the form window, one can simply click on the title bar of the form in the designer and type the new title.
What is the purpose of the 'Toolbox' in a Windows Forms application?
-The 'Toolbox' in a Windows Forms application is used to drag and drop components such as buttons, labels, and text boxes onto the form.
How can one anchor a control to a specific side or corner of the form?
-To anchor a control, one can select the control, go to the 'Properties' window, find the 'Anchor' property, and choose the desired side or corner from the drop-down options.
What is the code that needs to be written to display a message box with the text entered in a text box when a button is clicked?
-The code to display a message box with the text from a text box involves creating a string variable to store the text from the text box, and then using the 'MessageBox.Show' method to display the text when the button is clicked.
How does one run the Windows Form application after writing the code?
-After writing the code, one can run the Windows Form application by clicking on the 'Start' button or the green play icon in Visual Studio.
Outlines
💻 Creating Your First Windows Form Application
The video begins with a tutorial on creating a Windows Form application using C# in Visual Studio. The presenter guides viewers through the process of opening Visual Studio and initiating a new project. They emphasize selecting the 'Windows Form Application' option and choosing the .NET Core framework. The presenter then demonstrates how to name the project, avoiding spaces, and proceed with the creation. Upon project creation, they introduce the solution explorer and the main form file, explaining how to open the designer view. The video shows how to customize the form's title and manipulate its properties, such as font size and behavior, using the properties window. The presenter also explains how to use the toolbox to add components like buttons, labels, and text boxes to the form.
🔧 Customizing Form Components and Behavior
In this segment, the presenter focuses on customizing the form's components and their behavior. They demonstrate how to change the text of a label and anchor it to different sides of the form to ensure it resizes appropriately when the form's dimensions change. The video also covers how to adjust the button's text and anchor it to the bottom of the form. The presenter explains the use of the properties window to modify the appearance and behavior of form elements. They show how to change the background color of the form and its components. The video then transitions into writing code to create an interaction where text entered in a text box is displayed in a message box when a button is clicked. The presenter provides a step-by-step guide on how to write this functionality, including creating a string variable to store the text from the text box and using a message box to display it.
🚀 Running and Testing the Application
The final part of the video script describes the process of running and testing the newly created Windows Form application. The presenter instructs viewers to save their code and use the run icon in Visual Studio to execute the application. They demonstrate the application's responsive design, showing how the form's components resize and adjust as the form's size changes. The presenter tests the functionality of the 'click me' button, which triggers a message box displaying the text entered in the text box. The video concludes with the presenter expressing hope that the viewers enjoyed the tutorial and hints at future content by mentioning the next video.
Mindmap
Keywords
💡Windows Form Application
💡Visual Studio
💡C#
💡.NET Core
💡Project
💡Designer
💡Components
💡Properties
💡Anchor
💡Event Listener
💡Message Box
Highlights
Introduction to creating a Windows Form application in C# using Visual Studio.
Creating a new project in Visual Studio and selecting the Windows Form application template.
Choosing the .NET Core framework for the Windows Form application.
Naming the project and setting up the framework version.
Overview of the project solution and form file structure in Visual Studio.
Accessing the form designer to modify the form's appearance.
Changing the form's title to customize the application's name.
Using the toolbox to add components like buttons and labels to the form.
Customizing component properties such as text and anchoring.
Adjusting the form's behavior and appearance through properties.
Demonstration of resizing components and form with anchoring.
Changing the background color of the form and its components.
Writing code to handle button click events and display text from a textbox.
Using the MessageBox component to display user input.
Explanation of how to retrieve text from a textbox and use it in code.
Running the application to test the functionality of the form and components.
Demonstration of the form resizing and button click functionality in action.
Conclusion and invitation to the next video in the series.
Transcripts
hey guys in this video I'm going to show
you how you can create your first
Windows Form application since C sharp
on your Visual Studio
so let's get started and let's see how
we can do it
so when you open Visual Studio it will
look like this here we are going to
create a new project so just click on
create a new project
and then here either you can search for
Windows Form application or you can just
select these drop Doms and select C
sharp here and the platform will be
desktop so you can just select windows
for example and then you can choose the
all project type and the project type
here is desktop and from here you can
see two Windows Form app options so here
we can select this option which is
Windows Form app using.net core so just
select this option and then click on
next
on the next window you can give the name
of your project I'm going to name my
project as my first project for example
and you can see I don't like to give
spaces in the project name so if
possible just write or give a project
name without spaces right and then click
on next
and here the framework will be dot net
6.0 or whatever is the latest version of
dotnet in my case it's dotnet 6.0 click
on create
and this is going to create a Windows
Form application in c-sharp for you so
now you can see my project has been
created
you will be able to see this kind of
solution on the left hand side and on
the right hand side you can see this
form one dot CS file so this is the
program file where you will write the
program
now how you can open the designer you
can see this form one dot CS file right
and when you just expand this uh you
will be able to see C sharp form one
designer also here right so when you
double click on this form one dot CS
file it's also going to open the
designer for you so just wait for the
designer to load for this form one so
now you can see this form one dot CS
design window is open
you can resize
this form one window here you can even
give the title to it right now the title
here is form one you can change the text
of this let's say you want to change the
text to uh my app and then press enter
the title has been changed to my app
right so you can change the text for
your form by just changing the title
here you have all the other options to
change the appearance of your form or
you can even change the font size
if you are using some fonts in your form
or you can also change the behavior of
your form so you can drag and drop some
components in your form from the toolbox
so if you don't see the toolbox just
click on this toolbox option here which
is going to load all the toolbox if you
want to pin the toolbox
window you can just click on pin and to
box window will be pinned here so you
can easily drag and drop all the
components from here
so you can see
all Windows Form components you can see
buttons labels and other components
I'm going to use a button so I'm going
to just drag and drop this button into
my form I can even use the label so I
can drag and drop this label into my
form
and let me also use the text box so let
me search for
this text box and put it here okay
so I can
you can see a drag and drop all these
components here now for this label
I can change the label text
from this
properties window so the text here is
label one I can just write
enter some text for example or enter
your value because I want the user to
enter something into the text box right
so I'm going to just write enter
some
text here and then press enter and you
can see this label shows that I will
just drag this text box here also
and now
in the behavior you will be able to see
uh all these Behavior options
I want to change the anchor option here
so you can see the anchor is right now
top and left I can even
click on this option to Anchor it to the
right side so what it's going to do is
let me just
resize it according to my form
and I can even
do the same for this label but I do not
need this for the label
so what I it's going to do is when I
anchor it to the right when I resize my
window you can see the text box resizes
right
same I can do with the button also so
this button text says button one I'm
going to just change it to
click me for example
and then press enter and you can see the
button text is changed
I can even change the anchor for it so
right now it's top left I can anchor it
to the right and then I can just move it
here and
then just
resize my button
until it shows this kind of
line here right
so now
when I even resize my window it's going
to uh
just resize according to the width of my
frame right I can even anchor this
button to the bottom so that
it moves to the bottom let's see how can
we do that so I can anchor it to the
bottom and then
what happens is when I just make it
bigger this button size becomes bigger
for example right so this is how you can
change the behavior so you need to play
with all these options and see what you
can do
for example I can change the background
color from here
so here I have all these options for
changing the background color
let's say I want to just choose this one
and then you can see the background
color of my form has been changed and
the background color of my button also
has been changed
so now let's write some code so what I
want to do here is whenever some text is
entered into this text box and when I
click the button I want to open a
message box with the same text for
example right so
the main thing to note here is the name
of this text box so when I select this
text box the name of the text box is
text box one so for using this name I'm
going to use this text box text and show
the text on the message box for example
right so just copy this ah name from
here and then select your click me
button just double click on this button
which is going to
create a listener for your button right
so the button name was Button one you
can even verify that by going here and
then you can see the name of this button
you can see the name of the button is
button one and the method which is
created is button one click listener
right so let me just write some code I'm
going to create a
string variable I am going to name it as
text is equal to and I am going to take
the name of my text box right which was
text box one so I'm going to just write
Dot
text which is going to uh
give me the text whatever I write in the
text box it's going to just take the
text and assign it to the text variable
right now I want to show this text into
a message box so I can just use a
message box component just write
message box
dot show
and then
I can just write
U entered and then semicolon space and
then plus and then the text variable
which is text okay once you are done
just save your code and then you can run
your code by just clicking on this run
Icon so I'm going to run my code
and hopefully everything works fine you
can see my code is running
when I resize you can see the button and
the text box resizes according to the
size when I move down the button size is
changed right now let me enter something
so I'm going to just write
Dom here and then I'm going to click on
click me button and it says you entered
Dom right I can just write 34 here and
I'm going to just click on click me and
it says you entered 34 okay
so it is going to open this message box
every time when I click on the button
and it's going to show whatever text I
wrote here
so this is the basic Foundation of how
you can create a Windows Form
application in Visual Studio using C
sharp and create your forms and use your
forms in Windows Form application so I
hope you've enjoyed this video and I
will see you in the next video
Weitere ähnliche Videos ansehen
Generate C# Model from existing Microsoft SQL Server Database
Android application that uses GUI components, font and colors - 01
HTML Forms and Inputs | HTML5 Tutorial for Beginners
Asp.Net Core Web API Client/Server Application | Visual Studio 2019
How to Program A Calculator in C++! (Great C++ Microsoft Visual Studio Beginner Project)
Firebase phone authentication | Sign in | Phone country code | React phone input | Reactjs,firebase
5.0 / 5 (0 votes)