Friday, 28 June 2013

how to create a simple login application


Create new form insert two textboxes and labels infront of textboxes named as username and password
as shown in picture
select two buttons rename them as sign in and cancel as shown in picture

source code of form is:

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "abc" & textBox2.Text == "abc")
            {
                Form2 obj = new Form2();
                obj.ShowDialog();

            }
            else
            {
                MessageBox.Show("your username or password is incorrect");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult d;

           d = MessageBox.Show("you want to close this app", "Quit", MessageBoxButtons.YesNo);
           if (d ==DialogResult.Yes)
           {
               this.Close();
           }
        }
    }
}

No comments:

Post a Comment