Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you check and correct the codes and share the screenshot of the output? Please upload the screenshot. using System; using System.Windows.Forms; namespace UserInfoFormApp {

Can you check and correct the codes and share the screenshot of the output? Please upload the screenshot.
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 buttonSubmit
_
Click
(
object sender
,
EventArgs e
)
{
/
/
Get user input
string name
=
textBoxName.Text.Trim
(
)
;
string surname
=
textBoxSurname.Text.Trim
(
)
;
int age;
if
(
!
int.TryParse
(
textBoxAge
.
Text, out age
)
)
{
MessageBox.Show
(
"
Please enter a valid age.", "Error", MessageBoxButtons.OK
,
MessageBoxIcon.Error
)
;
return;
}
string gender
=
GetSelectedGender
(
)
;
string city
=
textBoxCity.Text.Trim
(
)
;
/
/
Validate input
if
(
string
.
IsNullOrEmpty
(
name
)
|
|
string.IsNullOrEmpty
(
surname
)
|
|
string.IsNullOrEmpty
(
gender
)
|
|
string.IsNullOrEmpty
(
city
)
)
{
MessageBox.Show
(
"
Please fill in all fields.", "Error", MessageBoxButtons.OK
,
MessageBoxIcon.Error
)
;
return;
}
/
/
Display welcome message
string welcomeMessage
=
$"Welcome,
{
name
}
{
surname
}
!
Age:
{
age
}
Gender:
{
gender
}
City:
{
city
}
"
;
MessageBox.Show
(
welcomeMessage
,
"Welcome", MessageBoxButtons.OK
,
MessageBoxIcon.Information
)
;
/
/
Clear the form after submission
ClearForm
(
)
;
}
private string GetSelectedGender
(
)
{
if
(
radioButtonMale
.
Checked
)
return "Male";
else if
(
radioButtonFemale
.
Checked
)
return "Female";
else if
(
radioButtonOther
.
Checked
)
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
(
)
;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions