Hoşgeldin Misafir

C# 3 Hak Sistemi İle Form Girişi Yapımı

MiRaT

13 Kas 2017
2,077 Mesaj

Aktiflik

Seviye

Deneyim

TIM / GÖREV:
Merhaba Dostlar, Vericeğim Kodlar İle Programınıza 3 Hak İle Şifreli Bir Giriş Sistemi Sağlıyacaktır.---

-Öncelikle Gerekli Olanlar;---

2 adet Buton
2 adet Label
1 adet TextBox-
-
-

Form1---

Kod:
public Form1()
        {
            InitializeComponent();
        }
 
        private **** Form1_Load(object sender, EventArgs e)
        {
            //Esc'ye basıldığında İptal düğmesi aktif olsun
            this.CancelButton = button2;
            //Enter'e basıldığında Tamam düğmesi aktif olsun
            this.AcceptButton = button1;
        }
 
 
        int hak = 3; // 3 Hak Tanımlıyoruz
        private **** button1_Click(object sender, EventArgs e)
        {
            hak--; // Butona Her Basıldığında 1 eksiltiyoruz
            if (textBox1.Text == "123456") 
                this.DialogResult = DialogResult.OK; //Şifre Doğru Girilirse Formumuzu Açıyor
            else
            {
                textBox1.Text = "";
                this.Text = "Şifre Yanlış";
                 
                    if (hak == 0) // Eğer 3 Hakkınıda Kullanmış İse 
                    {
                        this.DialogResult = DialogResult.Cancel;
                        MessageBox.Show("Tüm Haklarınız Tükendi, Programı Açmaya Yetkiniz Bulunmuyor");
                    }
                    else // Hakları Sayıp Ekrana Yazıyoruz
                    {
                        label2.Visible = true;
                        label2.Text = "Kalan Hakkınız " +hak ;
                        MessageBox.Show("Şifre Yanlış \n \n  Kalan Hakkınız " + hak);
                    }
            }
        }
 
        private **** button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel; // İptal Butonuna Basıldığında Form Kapanıyor.
        }
Form2---

Kod:
public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
 
        private **** Form2_Load(object sender, EventArgs e)
        {
            Form1 form = new Form1();
            form.Text = "Şifre Girin..";
            form.ShowDialog(); //Şifre formunu göster
             
            if (form.DialogResult == DialogResult.Cancel)//Şifre bilinmemişse veya iptale basılmışsa programdan çık
            {
                Close();
            }
            else // Şifre Doğru Girildiyse
            {
                MessageBox.Show("Tebrikler Şifreyi Doğru Bildiniz");
            }
        }
    }