Merhaba arkadaşlar programlama öğrenmek için her zaman yeni örnekler denemelisiniz. Bunun için bugün sizlere c# İle 2 Forumlu Uçak Bileti Satın Alma Programı örneğini aktaracağız.2 forum bir program da nasıl kullanılır? Uçak Bileti Satın Alma programı nasıl yapılır? 2 Forumlu Uçak Bileti Satın Alma Programı nasıl kodlanır? Gibi sorularınızın cevabını bu içerikte bulabilirsiniz.
Kullanılması Gerekenler
C# ile 2 Forumlu Uçak Bileti Satın Alma programı örneğinde kullanılması gerekenler sırası ile şunlardır:
Form1 için 1 adet Button, 1 adet Timer ve 1 adet PictureBox
Form2 için 18 adet Button, 14 adet Label, 2adet TextBox, 1 adet Timer ve 4 adet PictureBox bu program için kullanılması gerekenlerdir.
Kod Alanı
Programımızın kullanım şekli şu şekildedir:
Bu program 2 formlu olduğu için 2 aşamalı bir program olmaktadır. Form 1 ile başlayalım. Form 1 de belli bir süre içerisinde butona tıklamanızı gerektirecek kodları yazıyoruz. Ondan sonra butona tıkladığı anda Form2 açılıyor. Belli süre içerisinde tıklamazsa yapılması gerekenleri kodla belirtiyoruz. Siz isterseniz bir mesaj ile hatırlatma yapabilir veya direkt uygulamadan çıkabilirsiniz.
Form 2 ye geldiğimiz anda ilk önce değişkenlerimizi atıyoruz ondan sonra açılışta butonlarımızın rengini beyaz olarak belirliyoruz. Ondan sonrası butonlar için çok basit bir hale geliyor. Eğer ilgili butonu beyaz ise boş koltuk oluyor ve TextBoxlara istenileni yazıyor ve sonra rezervasyon yap butonuna tıklayarak beyaz olan butonu mavi renge çeviriyoruz. Tabi ki bunu belli bir süre içerisinde yapıyoruz.
Bu program çok karmaşık gözükse de oldukça basit bir programdır. Adım adım ilerleme ve sonraki adımı düşünme yöntemimizi geliştirmek oldukça verimli bir programdır. Kod alanı içerisine küçük notlar düşerek sizlerin işinizi kolaylaştırmak istedik. Aslında her zaman dediğimiz için kendiniz kod alanı ve form alanını değiştirerek yapınız. Fakat kafanız karışabileceği için adım adım yapmaya çalışın. Şimdiden iyi çalışmalar ve kolaylıklar diliyoruz..
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
this.Hide();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pictureBox1.Right <= panel1.Left )
{
Random r1 = new Random();
int i = 0;
int[] resim = new int[5];
for (i = 0; i <= 4; i++)
{
resim[i] = r1.Next(1, 15);
}
pictureBox1.Left = pictureBox1.Left + resim[0];
}
else
{
timer1.Enabled = false;
}
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
public partial class Form2 : Form
{
int i, x = 18;
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.button1.BackColor = System.Drawing.Color.White;
this.button2.BackColor = System.Drawing.Color.White;
this.button3.BackColor = System.Drawing.Color.White;
this.button4.BackColor = System.Drawing.Color.White;
this.button5.BackColor = System.Drawing.Color.White;
this.button6.BackColor = System.Drawing.Color.White;
this.button7.BackColor = System.Drawing.Color.White;
this.button8.BackColor = System.Drawing.Color.White;
this.button9.BackColor = System.Drawing.Color.White;
this.button10.BackColor = System.Drawing.Color.White;
this.button11.BackColor = System.Drawing.Color.White;
this.button12.BackColor = System.Drawing.Color.White;
this.button13.BackColor = System.Drawing.Color.White;
this.button14.BackColor = System.Drawing.Color.White;
this.button15.BackColor = System.Drawing.Color.White;
this.button16.BackColor = System.Drawing.Color.White;
this.button17.BackColor = System.Drawing.Color.White;
this.button18.BackColor = System.Drawing.Color.White;
timer1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button1.BackColor = System.Drawing.Color.White;
}
else
{
button1.Text = textBox1.Text + " " + textBox2.Text;
this.button1.BackColor = System.Drawing.Color.Blue;
button1.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button2.BackColor = System.Drawing.Color.White;
}
else
{
button2.Text = textBox1.Text + " " + textBox2.Text;
this.button2.BackColor = System.Drawing.Color.Blue;
button2.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button3.BackColor = System.Drawing.Color.White;
}
else
{
button3.Text = textBox1.Text + " " + textBox2.Text;
this.button3.BackColor = System.Drawing.Color.Blue;
button3.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button4.BackColor = System.Drawing.Color.White;
}
else
{
button4.Text = textBox1.Text + " " + textBox2.Text;
this.button4.BackColor = System.Drawing.Color.Blue;
button4.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button5_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button5.BackColor = System.Drawing.Color.White;
}
else
{
button5.Text = textBox1.Text + " " + textBox2.Text;
this.button5.BackColor = System.Drawing.Color.Blue;
button5.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button6_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button6.BackColor = System.Drawing.Color.White;
}
else
{
button6.Text = textBox1.Text + " " + textBox2.Text;
this.button6.BackColor = System.Drawing.Color.Blue;
button6.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button7_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button7.BackColor = System.Drawing.Color.White;
}
else
{
button7.Text = textBox1.Text + " " + textBox2.Text;
this.button7.BackColor = System.Drawing.Color.Blue;
button7.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button8_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button8.BackColor = System.Drawing.Color.White;
}
else
{
button8.Text = textBox1.Text + " " + textBox2.Text;
this.button8.BackColor = System.Drawing.Color.Blue;
button8.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button9_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button9.BackColor = System.Drawing.Color.White;
}
else
{
button9.Text = textBox1.Text + " " + textBox2.Text;
this.button9.BackColor = System.Drawing.Color.Blue;
button9.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button10_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button10.BackColor = System.Drawing.Color.White;
}
else
{
button10.Text = textBox1.Text + " " + textBox2.Text;
this.button10.BackColor = System.Drawing.Color.Blue;
button10.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button11_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button11.BackColor = System.Drawing.Color.White;
}
else
{
button11.Text = textBox1.Text + " " + textBox2.Text;
this.button11.BackColor = System.Drawing.Color.Blue;
button11.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button12_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button12.BackColor = System.Drawing.Color.White;
}
else
{
button12.Text = textBox1.Text + " " + textBox2.Text;
this.button12.BackColor = System.Drawing.Color.Blue;
button12.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button13_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button13.BackColor = System.Drawing.Color.White;
}
else
{
button13.Text = textBox1.Text + " " + textBox2.Text;
this.button13.BackColor = System.Drawing.Color.Blue;
button13.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button14_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button14.BackColor = System.Drawing.Color.White;
}
else
{
button14.Text = textBox1.Text + " " + textBox2.Text;
this.button14.BackColor = System.Drawing.Color.Blue;
button14.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button15_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button15.BackColor = System.Drawing.Color.White;
}
else
{
button15.Text = textBox1.Text + " " + textBox2.Text;
this.button15.BackColor = System.Drawing.Color.Blue;
button15.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button16_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button16.BackColor = System.Drawing.Color.White;
}
else
{
button16.Text = textBox1.Text + " " + textBox2.Text;
this.button16.BackColor = System.Drawing.Color.Blue;
button16.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button17_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button17.BackColor = System.Drawing.Color.White;
}
else
{
button17.Text = textBox1.Text + " " + textBox2.Text;
this.button17.BackColor = System.Drawing.Color.Blue;
button17.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void button18_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("boş kaldı");
this.button18.BackColor = System.Drawing.Color.White;
}
else
{
button18.Text = textBox1.Text + " " + textBox2.Text;
this.button18.BackColor = System.Drawing.Color.Blue;
button18.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
i++;
x--;
label3.Text = "Dolu: " + i.ToString();
label4.Text = "Boş: " + x.ToString();
}
}
private void pictureBox3_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pictureBox3.Right <= panel1.Left &amp;&amp; pictureBox4.Right <= panel2.Left)
{
Random r1 = new Random(); // random ile değişkenler
int i = 0;
int[] resim = new int[5]; // değişkenimiz 5 kadar
for (i = 0; i <= 4; i++) // for döngüsü sokuyoruz
{
resim[i] = r1.Next(1, 15); // resimlerin hareketi
}
pictureBox3.Left = pictureBox3.Left + resim[0];
pictureBox4.Left = pictureBox4.Left + resim[1];
}
else
{
timer1.Enabled = false;
}
}
}
Bu uygulamada herhangi bir sorun yaşarsanız aşağıya yorum olarak bırakabilirsiniz. Bunun yanı sıra web sitemizdeki diğer hazır C# programlama örneklerine ulaşmak için bu linke tıklayabilirsiniz.

