1 Ekim 2014 Çarşamba

MenuStrip İle Başka Forma Geçmek


Dosya menüsünün altındaki yeni sekmesine çift tıklanır . Açılan yere göndermek istediğiniz formun adı yazılır.

private void yeniToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1.ActiveForm.Hide();
            Form2 form2 = new Form2();
            form2.Show();
        }


Kodun Çalıştırılmış Hali


Color Dialog ile Arkaplan Rengini Değiştirme

Aşağıdaki kod butonun içine yazılır .Form içine Dialogs Menüsünden Color Dialog  eklenir .

private void button1_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                this.BackColor = colorDialog1.Color;
            }
        }



Kodun Çalıştırılmış Hali


Metodlarla Dört işlem Yapma

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();
        }

    
        public int topla(int s1, int s2)
        {
            int sonuc;
           sonuc = s1 + s2;

           return sonuc;

        }
         public  int cıkar(int s1, int s2)
        {

            return s1 - s2;

        }
         public int carp(int s1, int s2)
        {

            return s1 * s2;

        }
          public int bol(int s1, int s2)
        {

            return s1 /s2;

        }




        private void button3_Click(object sender, EventArgs e)
        {
         textBox3 .Text = carp (Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text)).ToString ();
      
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

           textBox3 .Text = topla(Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text)).ToString ();
        }

        private void button2_Click(object sender, EventArgs e)
        {
           textBox3 .Text = cıkar(Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text)).ToString ();
        }

        private void button4_Click(object sender, EventArgs e)
        {
              textBox3 .Text =bol (Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text)).ToString ();
    }
        }
        }

Kodun Çalıştırılmış Hali


15 Temmuz 2014 Salı

Oturum Açma

Aşağıdaki tüm kodlar formun içinde yer alır.
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 kullanıcışifre
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Form2 form2 = new Form2();

        string sifre;

        string[] k = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "v", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };


        private void button1_Click(object sender, EventArgs e)
        {
            label6.Text = sifre;

            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" )
            {
                MessageBox.Show("Lütfen boş geçmeyiniz");

            }
            else if (textBox1.Text == "hafize" && textBox2.Text == "12345" && textBox3.Text == sifre)
            {
                
                form2.Show();
                this.Hide();
            }
            else
            {

                   Random r = new Random();
                    sifre = "";// her buton tıklandığında değişmesi için label içini boşaltıp tekrar yazdırıyorum
                    for (int i = 0; i < 6; i++)
                    {

                        sifre += k[r.Next(33)];

                    }


                    label6.Text = sifre; //doğrulama kodunu gösteren label

                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";

                    MessageBox.Show("şifreyi yanlış girdiniz");

                }
              
            }
       

       
        private void Form1_Load(object sender, EventArgs e)
        {
            Random r = new Random();

            for (int i = 0; i < 6; i++)
            {

                sifre += k[r.Next(33)];

            }

            label6.Text = sifre;//doğrulama kodunu gösteren label
        }

      
    }

}

Kodun Çalıştırılmış Hali

















Kullanıcı Adı =hafize
Şifre =12345
Doğrulama kodu da doğru girildiği an 2.form ekranımıza gelir . 

Doğrulama Kodu Oluşturma

Aşağıdaki tüm kodlar formun içinde yer alır.
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();
        }
        Form2 form2 = new Form2();

        string sifre;

        string[] k = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "v", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

        private void button1_Click(object sender, EventArgs e)
        {


            label2.Text = sifre;



            if (textBox1.Text == sifre) { form2.Show(); label2.Text = ""; }

            else
            {
                Random r = new Random();
                sifre = "";
                for (int i = 0; i < 6; i++)
                {
                  
                    sifre += k[r.Next(33)];

                }
               

                label2.Text = sifre;

                label1.Text = "Şifre hatalı";


            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Random r = new Random();

            for (int i = 0; i < 6; i++)

            {

            sifre +=k[r.Next(33)];

            }

            label2.Text = sifre;

           
        }
    }
}
     
   

Kodun Çalıştırılmış Hali



Girilen Sayının Faktöriyelini Bulma

Aşağıdaki kodlar anasayfa butonunun içine yazılır .

private void button1_Click(object sender, EventArgs e)
        {
            int sayi, i, f = 1;

            sayi = Convert.ToInt16(textBox1.Text);

            for (i = 1; i <= sayi; i++)
            {

                f = i * f;

            }
            label2.Text = "Sonuç = " + f;  

        }

Kodun Çalıştırılmış Hali


Butonu Gizleyip Gösterme

Aşağıdaki tüm kodlar formun içinde yer alır.

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

        private void radioButton1_CheckedChanged(object sender, EventArgs e)//gizle radio butonu

        {
            button1.Visible = false;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)//göster radio butonu
        {
            button1.Visible = true ;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}


Kodun Çalıştırılmış Hali


Girilen Üniversiteye Ait Kodu Gösterme

Aşağıdaki tüm kodlar formun içinde yer alır.
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;

using System.Collections; //bunu eklemeyi unutmayın yoksa tablo çalışmaz !
namespace Girilen_Üniversiteye_Ait_Kodu_Gösterme
{
    public kısmi class Form1 : Form
    {
        public Form1 ()
        {
            InitializeComponent ();
        }
        Hashtable Tablo = new Hashtable ();

        dize [] = {üniversite "Kocatepe Üniversitesi" , "Boğaziçi Üniversitesi" , "Marmara Üniversitesi" , "istanbul Üniversitesi" , "19 Mayıs Üniversitesi" , "Ankara Üniversitesi" , "Ege Üniversitesi" ;}

        dize [] kodlar = { "01" , "02" , "03" , "04" , "05" , "06" , "07" ;}

        özel void Form1_Load ( object sender, EventArgs e)
        {

            için ( int i = 0; i üniversite.Length <; i + +)
            {

                tablo.Add (üniversite [i], kodlar [i]);

            }

        }
        özel void button1_Click ( object sender, EventArgs e)
        {
            Boole makarnalık = tablo.ContainsKey (TextBox1.Text);

           Eğer (durum == true )

{

. label2.Text = Tablo [TextBox1.Text] ToString ();

}

else MessageBox göster (. "Bulunamadı" );

}

        özel void Form1_Load_1 ( object sender, EventArgs e)
        {
            için ( int i = 0; i üniversite.Length <; i + +)
            {

                tablo.Add (üniversite [i], kodlar [i]);

            }
        }

        özel void label1_Click ( object sender, EventArgs e)
        {

        }

}
        }

Kodun Çalıştırılmış Hali


        

14 Temmuz 2014 Pazartesi

Sayfa Sayısını Bulma

Aşağıdaki kodlar hesapla Sayfa Sayısını Bul butonun içine yazılır .

private void button1_Click(object sender, EventArgs e)
        {
            int sayi1,i,toplam,say;
            say = 0;
            toplam = 0;
            sayi1 = Convert.ToInt16(textBox1.Text);
          
           
            if (sayi1 < 10)
            {
                for (i = 1; i <= sayi1; i++)
                {
                    say++;
                   
                }
                toplam = say;
                label4.Text = "Kullanılan toplam Rakam :" + toplam;

            }
            else if (sayi1 < 100)
            {
                for (i = 10; i <= sayi1; i++)
                {
                    say++;

                }
                toplam = say * 2 + 9;
                label4.Text = "Kullanılan toplam Rakam :" + toplam;
            }
            else if (sayi1 < 1000)
            {
                for (i = 100; i <= sayi1; i++)
                {
                    say++;

                }
                toplam = say * 3 + 99;
                label4.Text = "Kullanılan toplam Rakam :" + toplam;
            }
            else { label4.Text = "999' e kadar hesaplar:)"; }

        }

Kodun Çalıştırılmış Hali