Create a form in C# Windows Form, having personal Information of the user. Name (in text box) Roll no (in text box) Session (combo box F-2017, F-2018, F-2019, F-2020, F-2021) Email (textbox) nationality (combo Box button Pakistani/ non Pakistani) Religion (Combo Box/Radio Button Muslim/ non Muslim). After entering each information everything should be displayed in listbox.
namespace PersonalInformation
{
partial class frmMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnAdd = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtRollNo = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.cbSession = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.txtEmail = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.cbNationality = new System.Windows.Forms.ComboBox();
this.rbMuslim = new System.Windows.Forms.RadioButton();
this.rbNonMuslim = new System.Windows.Forms.RadioButton();
this.label6 = new System.Windows.Forms.Label();
this.lstPersons = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(102, 200);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(143, 23);
this.btnAdd.TabIndex = 0;
this.btnAdd.Text = "Add";
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(28, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Name:";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(102, 25);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(143, 20);
this.txtName.TabIndex = 2;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(28, 54);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(43, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Roll no:";
//
// txtRollNo
//
this.txtRollNo.Location = new System.Drawing.Point(102, 51);
this.txtRollNo.Name = "txtRollNo";
this.txtRollNo.Size = new System.Drawing.Size(143, 20);
this.txtRollNo.TabIndex = 2;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(28, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(47, 13);
this.label3.TabIndex = 1;
this.label3.Text = "Session:";
//
// cbSession
//
this.cbSession.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbSession.FormattingEnabled = true;
this.cbSession.Items.AddRange(new object[] {
"F-2017",
"F-2018",
"F-2019",
"F-2020",
"F-2021"});
this.cbSession.Location = new System.Drawing.Point(102, 77);
this.cbSession.Name = "cbSession";
this.cbSession.Size = new System.Drawing.Size(143, 21);
this.cbSession.TabIndex = 3;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(28, 107);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(35, 13);
this.label4.TabIndex = 1;
this.label4.Text = "Email:";
//
// txtEmail
//
this.txtEmail.Location = new System.Drawing.Point(102, 104);
this.txtEmail.Name = "txtEmail";
this.txtEmail.Size = new System.Drawing.Size(143, 20);
this.txtEmail.TabIndex = 2;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(28, 133);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(59, 13);
this.label5.TabIndex = 1;
this.label5.Text = "Nationality:";
//
// cbNationality
//
this.cbNationality.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbNationality.FormattingEnabled = true;
this.cbNationality.Items.AddRange(new object[] {
"Pakistani",
"Non Pakistani"});
this.cbNationality.Location = new System.Drawing.Point(102, 130);
this.cbNationality.Name = "cbNationality";
this.cbNationality.Size = new System.Drawing.Size(143, 21);
this.cbNationality.TabIndex = 3;
//
// rbMuslim
//
this.rbMuslim.AutoSize = true;
this.rbMuslim.Checked = true;
this.rbMuslim.Location = new System.Drawing.Point(102, 167);
this.rbMuslim.Name = "rbMuslim";
this.rbMuslim.Size = new System.Drawing.Size(57, 17);
this.rbMuslim.TabIndex = 4;
this.rbMuslim.TabStop = true;
this.rbMuslim.Text = "Muslim";
this.rbMuslim.UseVisualStyleBackColor = true;
//
// rbNonMuslim
//
this.rbNonMuslim.AutoSize = true;
this.rbNonMuslim.Location = new System.Drawing.Point(165, 167);
this.rbNonMuslim.Name = "rbNonMuslim";
this.rbNonMuslim.Size = new System.Drawing.Size(80, 17);
this.rbNonMuslim.TabIndex = 4;
this.rbNonMuslim.Text = "Non Muslim";
this.rbNonMuslim.UseVisualStyleBackColor = true;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(28, 169);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 13);
this.label6.TabIndex = 1;
this.label6.Text = "Religion:";
//
// lstPersons
//
this.lstPersons.FormattingEnabled = true;
this.lstPersons.Location = new System.Drawing.Point(270, 25);
this.lstPersons.Name = "lstPersons";
this.lstPersons.Size = new System.Drawing.Size(505, 199);
this.lstPersons.TabIndex = 5;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(807, 246);
this.Controls.Add(this.lstPersons);
this.Controls.Add(this.rbNonMuslim);
this.Controls.Add(this.rbMuslim);
this.Controls.Add(this.cbNationality);
this.Controls.Add(this.cbSession);
this.Controls.Add(this.txtEmail);
this.Controls.Add(this.txtRollNo);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnAdd);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = " Personal Information";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtRollNo;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox cbSession;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtEmail;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox cbNationality;
private System.Windows.Forms.RadioButton rbMuslim;
private System.Windows.Forms.RadioButton rbNonMuslim;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.ListBox lstPersons;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PersonalInformation
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
cbNationality.SelectedIndex = 0;
cbSession.SelectedIndex = 0;
}
/// <summary>
/// Add button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAdd_Click(object sender, EventArgs e)
{
string selectedReligion="Muslim";
if (rbNonMuslim.Checked) {
selectedReligion = "Non Muslim";
}
lstPersons.Items.Add(txtName.Text + " " + txtRollNo.Text + " " + cbSession.SelectedItem.ToString() + " " + txtEmail.Text + " " + cbNationality.SelectedItem.ToString() + " " + selectedReligion);
}
}
}
Comments
Leave a comment