Getting Started with WinForms
C-Sharp Learning Part 2
Hey everyone! In this article we are gonna see how to build our first app in C# using .NET. If you haven't installed Visual Studio click here.
First open Visual Studio 2022:
You will be presented with this screen:
Click on Create a new Project. You will get this:Search for "WinForms" in the search box and just select it and click next.
Name your app in this screen and select the location of your Project and click Next:
Please note that it might take some time if the Designer button is not present in the View Menu. If it is taking a lot of time, then please reopen your project.
Let us get started with each control in the toolbox. If you don't see the toolbox, then click View and select Toolbox at the bottom.
For starters, let's just create a very simple app.
First add a button from the toolbox to Form1 by dragging it. You can resize the button however you want:
Properties Tab and double click in the Click Event of the button:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hi! This is my first app.");
}
Now, click on the button at the top which has the Play Icon and your app name:
After building your App, your App runs!
Click on the button and you got a messagebox!
Now for a more detailed MessageBox:
Stop Debugging by closing your app.
For a Title in the Messagebox:
Just add a piece of string next to it:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hi! This is my first app.", "Message");
}
For customizing the buttons:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hi! This is my first app.", "Message", MessageBoxButtons.OK);
}
For an icon:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hi! This is my first app.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Now just run it again:
Please Note: Since I am using Windows 11 Icons in Windows 10, the icons in the MessageBox may differ than the icons in your MessageBox even though you're running Windows 10.
For the Previous Tutorial, Click Here
For the Next Tutorial, Click Here
Comments
Post a Comment