Thursday, July 1, 2021

Winform Registration Form basic code





Register.cs

using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace WinFormsAppx1
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }
        private void Register_Load(object sender, EventArgs e)
        {
            listBoxHobbies.Items.Add("Cricket");
            listBoxHobbies.Items.Add("Net Surfing");
            listBoxHobbies.Items.Add("Science");
            listBoxHobbies.Items.Add("Playing Cards");
            listBoxHobbies.Items.Add("Poetry");
            listBoxHobbies.Items.Add("Painting");
            listBoxHobbies.Items.Add("Dance");
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comboBox1 = (ComboBox)sender;
            int comboIndex = comboBox1.SelectedIndex;
            string comboItem = comboBox1.SelectedItem.ToString();
            //MessageBox.Show(comboItem);
        }

        private void btnPicture_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFiledlg = new OpenFileDialog();
            openFiledlg.Title = "Select Image";
            string strInitialDir = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            openFiledlg.InitialDirectory = strInitialDir;
            openFiledlg.Filter = "Image files (*.png)|*.png|All files (*.*)|*.*";
            DialogResult dlgResult =  openFiledlg.ShowDialog();
            if (dlgResult.Equals(DialogResult.OK))
            {
                string filename = openFiledlg.FileName;
                pictureBox1.ImageLocation = filename;
                pictureBox1.Image = new Bitmap(filename);
            }

        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
             ListBox listBox1 = (ListBox)sender;
            string curItem = listBox1.SelectedItem.ToString();
            int indexSelected = listBox1.SelectedIndex;
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
                string username = txtUsername.Text;
                string email = txtEmail.Text;
                string password = txtPassword.Text;
                string confirmPassword = txtConfirmPassword.Text;
            try
            {
                string qualification = cboQualification.SelectedItem.ToString();
                string gender = groupBox1.Controls.OfType().FirstOrDefault(r => r.Checked).Text;
                string hobbies = listBoxHobbies.SelectedItem.ToString();
                string imgpath = pictureBox1.ImageLocation;
            }
            catch (NullReferenceException ex)
            {

                MessageBox.Show("Fill or select all controls.",ex.Message);
            }
        }


    }
}
Register.Designer.cs

namespace WinFormsAppx1
{
    partial class Register
    {
        /// 
        /// Required designer variable.
        /// 
        private System.ComponentModel.IContainer components = null;

        /// 
        /// Clean up any resources being used.
        /// 
        /// true if managed resources should be disposed; otherwise, false.
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// 
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// 
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.txtUsername = new System.Windows.Forms.TextBox();
            this.txtEmail = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.txtPassword = new System.Windows.Forms.TextBox();
            this.txtConfirmPassword = new System.Windows.Forms.TextBox();
            this.optionMale = new System.Windows.Forms.RadioButton();
            this.optionFemale = new System.Windows.Forms.RadioButton();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.listBoxHobbies = new System.Windows.Forms.ListBox();
            this.cboQualification = new System.Windows.Forms.ComboBox();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.btnPicture = new System.Windows.Forms.Button();
            this.label5 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.btnSave = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(30, 62);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(67, 17);
            this.label1.TabIndex = 0;
            this.label1.Text = "Username";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(30, 128);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(64, 17);
            this.label2.TabIndex = 0;
            this.label2.Text = "Password";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(30, 95);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(39, 17);
            this.label3.TabIndex = 0;
            this.label3.Text = "Email";
            // 
            // txtUsername
            // 
            this.txtUsername.Location = new System.Drawing.Point(124, 62);
            this.txtUsername.Name = "txtUsername";
            this.txtUsername.Size = new System.Drawing.Size(200, 25);
            this.txtUsername.TabIndex = 1;
            // 
            // txtEmail
            // 
            this.txtEmail.Location = new System.Drawing.Point(124, 94);
            this.txtEmail.Name = "txtEmail";
            this.txtEmail.Size = new System.Drawing.Size(200, 25);
            this.txtEmail.TabIndex = 2;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(30, 161);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(64, 17);
            this.label4.TabIndex = 0;
            this.label4.Text = "Password";
            // 
            // txtPassword
            // 
            this.txtPassword.Location = new System.Drawing.Point(124, 126);
            this.txtPassword.MaxLength = 20;
            this.txtPassword.Name = "txtPassword";
            this.txtPassword.PasswordChar = '*';
            this.txtPassword.Size = new System.Drawing.Size(200, 25);
            this.txtPassword.TabIndex = 3;
            // 
            // txtConfirmPassword
            // 
            this.txtConfirmPassword.Location = new System.Drawing.Point(124, 158);
            this.txtConfirmPassword.MaxLength = 20;
            this.txtConfirmPassword.Name = "txtConfirmPassword";
            this.txtConfirmPassword.PasswordChar = '*';
            this.txtConfirmPassword.Size = new System.Drawing.Size(200, 25);
            this.txtConfirmPassword.TabIndex = 4;
            // 
            // optionMale
            // 
            this.optionMale.AutoSize = true;
            this.optionMale.Location = new System.Drawing.Point(94, 14);
            this.optionMale.Name = "optionMale";
            this.optionMale.Size = new System.Drawing.Size(55, 21);
            this.optionMale.TabIndex = 5;
            this.optionMale.TabStop = true;
            this.optionMale.Text = "Male";
            this.optionMale.UseVisualStyleBackColor = true;
            // 
            // optionFemale
            // 
            this.optionFemale.AutoSize = true;
            this.optionFemale.Location = new System.Drawing.Point(165, 14);
            this.optionFemale.Name = "optionFemale";
            this.optionFemale.Size = new System.Drawing.Size(67, 21);
            this.optionFemale.TabIndex = 6;
            this.optionFemale.TabStop = true;
            this.optionFemale.Text = "Female";
            this.optionFemale.UseVisualStyleBackColor = true;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.optionFemale);
            this.groupBox1.Controls.Add(this.optionMale);
            this.groupBox1.Location = new System.Drawing.Point(30, 220);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(294, 43);
            this.groupBox1.TabIndex = 7;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Gender";
            // 
            // listBoxHobbies
            // 
            this.listBoxHobbies.FormattingEnabled = true;
            this.listBoxHobbies.ItemHeight = 17;
            this.listBoxHobbies.Location = new System.Drawing.Point(124, 269);
            this.listBoxHobbies.Name = "listBoxHobbies";
            this.listBoxHobbies.Size = new System.Drawing.Size(200, 89);
            this.listBoxHobbies.TabIndex = 8;
            this.listBoxHobbies.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
            // 
            // cboQualification
            // 
            this.cboQualification.FormattingEnabled = true;
            this.cboQualification.Items.AddRange(new object[] {
            "B.A.",
            "B.Sc.",
            "M.A.",
            "Ph.D."});
            this.cboQualification.Location = new System.Drawing.Point(124, 189);
            this.cboQualification.Name = "cboQualification";
            this.cboQualification.Size = new System.Drawing.Size(200, 25);
            this.cboQualification.TabIndex = 9;
            this.cboQualification.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
            // 
            // pictureBox1
            // 
            this.pictureBox1.BackColor = System.Drawing.SystemColors.ButtonHighlight;
            this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.pictureBox1.Location = new System.Drawing.Point(364, 62);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(165, 121);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            this.pictureBox1.TabIndex = 10;
            this.pictureBox1.TabStop = false;
            // 
            // btnPicture
            // 
            this.btnPicture.Location = new System.Drawing.Point(411, 203);
            this.btnPicture.Name = "btnPicture";
            this.btnPicture.Size = new System.Drawing.Size(118, 28);
            this.btnPicture.TabIndex = 8;
            this.btnPicture.Text = "Select Image";
            this.btnPicture.UseVisualStyleBackColor = true;
            this.btnPicture.Click += new System.EventHandler(this.btnPicture_Click);
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(30, 192);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(80, 17);
            this.label5.TabIndex = 11;
            this.label5.Text = "Qualification";
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Font = new System.Drawing.Font("Segoe UI", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
            this.label6.Location = new System.Drawing.Point(183, 15);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(203, 28);
            this.label6.TabIndex = 8;
            this.label6.Text = "REGISTRATION FORM";
            // 
            // btnSave
            // 
            this.btnSave.Location = new System.Drawing.Point(421, 324);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(108, 34);
            this.btnSave.TabIndex = 12;
            this.btnSave.Text = "Save";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.Location = new System.Drawing.Point(421, 284);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(108, 34);
            this.btnCancel.TabIndex = 12;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // Register
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(555, 432);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.listBoxHobbies);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.btnPicture);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.cboQualification);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.txtConfirmPassword);
            this.Controls.Add(this.txtPassword);
            this.Controls.Add(this.txtEmail);
            this.Controls.Add(this.txtUsername);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label1);
            this.Name = "Register";
            this.Text = "Save";
            this.Load += new System.EventHandler(this.Register_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox txtUsername;
        private System.Windows.Forms.TextBox txtEmail;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox txtPassword;
        private System.Windows.Forms.TextBox txtConfirmPassword;
        private System.Windows.Forms.RadioButton optionMale;
        private System.Windows.Forms.RadioButton optionFemale;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.ListBox listBoxHobbies;
        private System.Windows.Forms.ComboBox cboQualification;
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.Button btnPicture;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Button btnSave;
        private System.Windows.Forms.Button btnCancel;
    }
}

No comments:

Post a Comment

Hot Topics