Question
PLEASE I NEED C# PROGRAM Tasks This lab has four parts: 1. Create a window. 2. Create 5 buttons in that window. 3. Create an
PLEASE I NEED C# PROGRAM
Tasks This lab has four parts:
1. Create a window.
2. Create 5 buttons in that window.
3. Create an event when a button is pushed.
4. Create an event listener that will respond to the button being pushed event.
Task 1 Create a Window The first step to creating a GUI application is to use the correct project type. From this point on,
For C#: Please select the Windows Form Application. Now that we have a project set up to work with a GUI, let us get into the specifics on how to make a window.
1. NOTE: After the project finishes being made, the first page that should appear is the one with the window already made. So you should see a blank white window in the center panel instead of the code you would normally find there when making a console application.
2. In order to see the code and be able to change it, please find the Solution Explorer panel which should be on the right. Find the Form1.cs file and click on the dropdown arrow to see the Form1.Designer.cs file and double click on it to open it. NOTE: We still have a Program.cs file, however if you open it, it will only contain a few lines of code inside the Main method.
3. Now you should see the code behind the design of the window. However, do NOT write any code here yet.
4. We have already made our window, congratulations! (Feel free to change the look and size of the window using the Properties panel.)
Task 2 Create Buttons We can make many types of interact-able objects in our window, but we will keep it simple and use a clickable button.
For C#: 1. First, go back to the Form1.cs file so that we can see the blank white window.
2. Please find the toolbox pop-out menu on the left side bar. Click on it to pop-out the menu.
3. Go to the menu tab called All Windows Forms and click once on the choice/item Button.
4. Move the mouse cursor back over the blank white page and you should notice the cursor changes into a point with the Button icon on the lower right.
5. Clicking on the window will create a default button with a default size on that window. You may also click and drag to create a button with the size of the area your cursor moved over. Make sure to add the remaining buttons.
NOTE: The code in our Form1.Designer.cs file has changed, by adding a button object at the bottom of the code.
Task 3
Create an Event At this point, we will want to create an event object every time the button is pushed. This way we will be able to tell when the button is pushed and what to do when it is pushed.
For C#:
1. To add an event object for clicking on the button, simply double click on the button in the window.
2. This will immediately take us to the Form1.cs file where a new method will have been created for us named button1_Click.
3. We have added the ability of the button to create events after being clicked (even without writing anything into the new click method)!
Task 4 Create an Event Listener Lastly, we will create an event listener to handle the events (buttons being pushed) and display a message, on the GUI, saying which number button was pushed.
For C#:
1. First we will need to create a text box on the window so that we can display our message. Follow similar steps for creating the buttons, but this time look for the item TextBox.
2. Return to the Form1.cs file with our button1_click method. Using the new textbox object and the parameter object sender, write some code into the method so that the number of the sender (which was the button) displays in the text region of the textbox.
3. We have finished the lab when all 5 of our buttons have this ability. NOTE: The method button1_click is the event listener and it is handling events after the button is clicked and creates that EventArgs e event that is the second parameter in that method. Below is some possible sample output (note: simply means, there exists):
Some Sample Output: Before button 1 is clicked:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started