Question: using System; using System.Windows.Forms; namespace UserInfoFormApp { public partial class MainForm : Form { public MainForm ( ) { InitializeComponent ( ) ; InitializeGenderRadioButtons (
using System;
using System.Windows.Forms;
namespace UserInfoFormApp
public partial class MainForm : Form
public MainForm
InitializeComponent;
InitializeGenderRadioButtons;
private void InitializeGenderRadioButtons
Gender radio buttons
radioButtonMale.Text "Male";
radioButtonFemale.Text "Female";
radioButtonOther.Text "Other";
private void buttonSubmitClickobject sender EventArgs e
Get user input
string name textBoxName.Text.Trim;
string surname textBoxSurname.Text.Trim;
int age;
if int.TryParsetextBoxAgeText, out age
MessageBox.ShowPlease enter a valid age.", "Error", MessageBoxButtons.OK MessageBoxIcon.Error;
return;
string gender GetSelectedGender;
string city textBoxCity.Text.Trim;
Validate input
if stringIsNullOrEmptyname string.IsNullOrEmptysurname string.IsNullOrEmptygender string.IsNullOrEmptycity
MessageBox.ShowPlease fill in all fields.", "Error", MessageBoxButtons.OK MessageBoxIcon.Error;
return;
Display welcome message
string welcomeMessage $"Welcome, namesurname
Age: age
Gender: gender
City: city;
MessageBox.ShowwelcomeMessage "Welcome", MessageBoxButtons.OK MessageBoxIcon.Information;
Clear the form after submission
ClearForm;
private string GetSelectedGender
if radioButtonMaleChecked
return "Male";
else if radioButtonFemaleChecked
return "Female";
else if radioButtonOtherChecked
return "Other";
else
return string.Empty;
private void ClearForm
textBoxName.Clear;
textBoxSurname.Clear;
textBoxAge.Clear;
radioButtonMale.Checked false;
radioButtonFemale.Checked false;
radioButtonOther.Checked false;
textBoxCity.Clear;
Can you check and correct the codes and share the screenshot of the output? Please upload the screenshot.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
