2 Aralık 2016 Cuma

C# ile Buttona Tıklanınca 1-10 Arası Sayı Yazdıran Program

namespace Örnek1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i;
            for (i = 1; i < 11; i++)
            {
                listBox1.Items.Add(i);
            }
        }
    }
}

C# ile Buttona Tıklandıkça Sayıyı Arttıran Program

namespace Örnek3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int sayi = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            sayi = sayi + 1;
            label1.Text = sayi.ToString();
        }
    }
}

C# ile Rasgele Sayı Üretip Hangi Sayının Büyük Olduğunu Kontrol Etme


namespace Örnek1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a, b;
            Random sayi = new Random();
            a = sayi.Next(0, 7);
            b = sayi.Next(0, 7);
            label1.Text = a.ToString();
            label2.Text = b.ToString();

            if(a>b)
            {
                label3.Text = "Soldaki Sayı Sağdakinden Büyüktür...";
            }
            else if(a==b)
            {
                label3.Text = "Sağdaki Sayı Soldaki Sayıya Eşittir...";
            }
            else
            {
                label3.Text = "Sağdaki Sayı Soldaki Sayıdan Büyüktür...";
            }
        }
    }
}

1 Aralık 2016 Perşembe

C# ile Kullanıcıcı Girişi Yaparak Formlar Arası Geçiş


namespace Örnek4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text=="admin"&& textBox2.Text=="1234")
            {
                Form2 yeni = new Form2();
                yeni.Show(this);
                this.Hide();
            }
            else
            {
                MessageBox.Show("Hatalı Giriş Yaptınız...");
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                textBox2.PasswordChar = '*';
            }
            else
                textBox2.PasswordChar = '\0';
        }
    }
}

C# ile Formlar Arası Geçiş Nasıl Yapılır ?


Form1'dan, Form2'ye geçiş yapmak için gerekli olan kodlar; 
namespace Örnek2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 yeni = new Form2();
            yeni.Show(this);
            Hide();
        }
    }

}

Form2'dan, Form1'ye geçiş yapmak için gerekli olan kodlar; 
namespace Örnek2
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

       private void Form2_FormClosed(object sender, FormClosedEventArgs e)
        {
            Owner.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 yeni = new Form1();
            yeni.Show(this);
            Hide();
        }
    }

C# ile Sınav Sonuçlarının Ortalamasını Hesaplama ve Harf Notu Belirleme

namespace OrtalamaHesapla
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double vize1, vize2, final, ortalama;
            vize1 = Convert.ToDouble(textBox1.Text);
            vize2 = Convert.ToDouble(textBox2.Text);
            final = Convert.ToDouble(textBox3.Text);
           
            if (final >= 80)
                label4.Text = "Tebrikle Yüksek Bir Final Notu Aldınız...";

            ortalama= vize1* 0.20+ vize2*0.20+final*0.60;
            label5.Text = "Ortalama:" + ortalama.ToString();

            if (ortalama>90)
                label6.Text="Harf Notu:A";
            else if (ortalama>75)
                label6.Text="Harf Notu:B";
            else if (ortalama > 60)
                label6.Text = "Harf Notu:C";
            else if (ortalama > 50)
                label6.Text = "Harf Notu:D";
            else
                label6.Text = "Harf Notu:F";

        }
    }
}

C# İle Karenin ve Dikdörtgenin Alanlarının ve Çevresinin Hesaplanması


C# Kodları..

namespace KareDikdortgenHesap
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            panel1.Visible = false;
            panel2.Visible = false;

        }

        private void kare_Click(object sender, EventArgs e)
        {
            panel1.Visible = true;
            panel2.Visible = false;
            textBox1.Text = "";
            label4.Text = "";
            label5.Text = "";
        }

        private void kareHesap_Click(object sender, EventArgs e)
        {
            int kenar;
            kenar = Convert.ToInt32(textBox1.Text);
            int alan = kenar * kenar;
            int cevre = 4 * kenar;
            label4.Text = alan.ToString();
            label5.Text = cevre.ToString();
        }

        private void dikdortgen_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
            panel2.Visible = true;
            textBox2.Text = "";
            textBox3.Text = "";
            label9.Text = "";
            label8.Text = "";
        }

        private void dikdortgenHesap_Click(object sender, EventArgs e)
        {
            int kısa = Convert.ToInt32(textBox2.Text);
            int uzun = Convert.ToInt32(textBox3.Text);
            int alan = kısa * uzun;
            int cevre = 2 * (kısa + uzun);
            label9.Text = alan.ToString();
            label8.Text = cevre.ToString();
        }
    }
}