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