10 Temmuz 2014 Perşembe

Ardışık Sayıların Toplamını Bulma


Aşağıdaki kodlar hesapla butonun içine yazılır .

 private void button1_Click(object sender, EventArgs e)
        {
            int sayi1, sayi2, sayi3, toplam, i,say;
            sayi1 =Convert.ToInt16 (textBox1.Text); //başlangıç butonu
            sayi2 =Convert.ToInt16 (textBox2.Text); //bitiş butonu
            sayi3 =Convert.ToInt16 (textBox3.Text); //artış miktarı butonu
            toplam = 0;
            say =0;

            for (i = sayi1; i <= sayi2; i++)
            {
                if (i % sayi3 == 0)
                { say++;
                    toplam = toplam + i;
                }
            }
            label4.Text ="Terim Sayısı= "+ say +"Toplam =" + toplam ;
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }


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



8 Temmuz 2014 Salı

Uygulama Dosyaları

Bu başlık altında yaptığım tüm örneklerin  uygulamalarını ara ara yayınlıyorum , ve yayınlamaya devam edeceğim.Herşey sizler için, takibe devam :)

12 Temmuz 2013 Cuma

Çarpışan İki Topun Yönlerini Değiştirmesi

Çalışma sayfamıza iki tane timer ekliyoruz. Sol taraftaki topun adı top1 , sağ taraftaki topu adı ise  
top2 dir.

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 Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

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

        private void Form3_Load(object sender, EventArgs e)
        {
            timer1.Stop();
            timer2.Stop();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
            timer2.Start();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            top1.Left = top1.Left + 10;
            top2.Left = top2.Left - 10;
            if (top1.Right > top2.Left) timer1.Stop();


        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (top1.Right > top2.Left) top1.Top = top1.Top + 10;
            if (top1.Right > top2.Left) top2.Top = top2.Top - 10;
        }
    }

}



5 Mayıs 2013 Pazar

Listbox a Girilen Aynı Değeri Eklememe


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();                 
        }
        string[] meyvalar = new string[100];
        int i = 0;
        int meyvavar = 0;// bayrak görevini görür.

        private void button1_Click(object sender, EventArgs e)
        {
            for (int sayaç = 0; sayaç < i; sayaç++)
            {
                if (meyvalar[sayaç] == textBox1.Text)
                {
                    MessageBox.Show("bu meyva daha önce eklendi");
                    textBox1.Text = ""; meyvavar = 1;// daha önce meyve girilmiştir anlamına geliyor.
                }
            }
            if (meyvavar == 0) // daha önce aynı meyve girilmemişse eğer anlamına geliyor.
            {
                listBox1.Items.Add(textBox1.Text);
                meyvalar[i] = textBox1.Text;
                textBox1.Text="";
            }
            meyvavar=0;
            i++;



        }
    }
}



 


4 Nisan 2013 Perşembe

C# Kodlarıyla Veritabanına Resim Ekleme

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.Data.OleDb;
namespace resim_ekleme
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        OleDbConnection bağlantı;
        OleDbCommand sqlkomutu;
        OleDbDataAdapter da;
        DataSet ds;


        private void güncelle()
        {
            da = new OleDbDataAdapter("Select * from tablo", bağlantı);
            ds = new DataSet();
            bağlantı.Open();
            da.Fill(ds, "tablo");
            bağlantı.Close();
            dataGridView1.DataSource = ds.Tables["tablo"];
        }



        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'listeDataSet1.tablo' table. You can move, or remove it, as needed.
            this.tabloTableAdapter1.Fill(this.listeDataSet1.tablo);
            bağlantı = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=liste.mdb");
            güncelle();

           

        }

        private void button1_Click(object sender, EventArgs e)  // Aç butonuna yazılır
        {
            pictureBox1.Visible = true;
            openFileDialog1.ShowDialog();
            pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);

        }
        int seçilensatır;

        private void button2_Click(object sender, EventArgs e) //Kaydet butonuna yazılır
        {
            try
            {

                string foto = openFileDialog1.FileName;
                //  bağlantı = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=liste.mdb");
                sqlkomutu = new OleDbCommand(
                    "update tablo set foto=@foto where Kimlik=" + seçilensatır, bağlantı);


                bağlantı.Open();
                sqlkomutu.Parameters.Add("@foto", OleDbType.Char, 250).Value = foto;


                sqlkomutu.ExecuteNonQuery();
                bağlantı.Close();
                güncelle();
            }
            catch
            {
               
            }
           
           
             
           
        }
        
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {

         
            try
            {
                seçilensatır = Convert.ToInt16(ds.Tables["tablo"].Rows[e.RowIndex]["Kimlik"]);

                if (ds.Tables["tablo"].Rows[e.RowIndex]["foto"].ToString() == "")
                    pictureBox1.Visible = false;
                else
                {
                    pictureBox1.Visible = true;
                    pictureBox1.Image = Image.FromFile(
                                         ds.Tables["tablo"].Rows[e.RowIndex]["foto"].ToString());
                }
            }
            catch { }
        }
    }
}





Veri tabanından Arama 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;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        OleDbConnection bağlantı;
        OleDbCommand sqlkomutu;
        OleDbDataAdapter da;
        DataSet ds;


        private void güncelle()
        {
            da = new OleDbDataAdapter("Select * from tablo", bağlantı);
            ds = new DataSet();
            bağlantı.Open();
            da.Fill(ds, "tablo");
            bağlantı.Close();
            dataGridView1.DataSource = ds.Tables["tablo"];
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            bağlantı = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=liste.mdb");
            güncelle();

            // TODO: This line of code loads data into the 'listeDataSet1.tablo' table. You can move, or remove it, as needed.
            this.tabloTableAdapter.Fill(this.listeDataSet1.tablo);

        }

        private void button1_Click(object sender, EventArgs e)  // Ara butonuna yazılır
        { da = new OleDbDataAdapter(
               "Select * from tablo where adı Like '" + textBox1.Text + "%'", bağlantı);// ½ işareti texbox sa girilen karakterden sonra sonuna hangi harf gelirse gelsin tümünü göster demektir.
            ds = new DataSet();
            bağlantı.Open();

            da.Fill(ds, "tablo");
            bağlantı.Close();
            dataGridView1.DataSource = ds.Tables["tablo"];
        
        }

        }
    }