OOP - Kenan Burak Ceylan Kişisel Blog

Download Report

Transcript OOP - Kenan Burak Ceylan Kişisel Blog

C# ile OOP
GİRİŞ
Windows Form Application
• New Project -> WindowsFormApplication
•
•
•
•
Form
Toolbox
Solution
Properties
Toolbox
• Forma eklenebilecek araçlar listesi
• Eklenen tüm araçlar ile ilgili kodlar
Form1.Designer içerisinde
tutuluyor.
Solution
• Projele dosyaları bir çözüm
altında toplanıyor.
•
•
•
•
Using ile kullanılan referans dosyaları
Program ayarlarının yapıldığı xml dosyası
Tasarım dosyası
Kod bölümü
Properties
• Form ve forma eklenen araçlara ait
özelliklerin düzenlendiği pencere
• Form aktif iken:








Text=>form başlığı
Name=>kod alanındaki isim
Icon=>formdaki icon
BackColor=>formun arka plan rengi
Size=>boyutu
Opacity=>saydamlık
Maximumsize=>form için max boyut belirlenebilir
Forecolor=>tool üzerindeki yazı rengi ayarlanabilir
• gibi form özellikleri değiştirilebilir
http://msdn.microsoft.com/tr-tr/library/system.windows.forms.checkedlistbox(v=vs.110).aspx
Örnek
private void button1_click(….)
{
MessageBox.Show(“Kayıt tamamlandı”);
}
private void button1_click(….)
{
string tx=“Kayıt tamamlandı”;
MessageBox.Show(“tx”);
}
Örnek
• Form Application (text->örnek)
• Button1(text->mesaj_1)
– Click event:
MessageBox -> (“Kaydet”);
• Button2(text->mesaj_2)
– Click event:
MessageBox -> (“Kayıt tamamlandı”,”bilgilendirme”);
• Button3(text->mesaj_3)
– Click event:
MessageBox -> (“Kayıt tamamlandı”,”bilgilendirme”,
MessageBoxButtons.OK,MessageBoxIcon.Information);
• Button4(text->mesaj_4)
– Click event:
MessageBox -> (“Bilgiler Eksik Girildi”,”bilgilendirme”,
MessageBoxButtons.OK,MessageBoxIcon.Warning);
• Button5(text->mesaj_5)
– Click event:
MessageBox -> (“Kayıt Yapılamadı”,”bilgilendirme”,
MessageBoxButtons.OK,MessageBoxIcon.Error);
• Button6(text->mesaj_6)
– Click event:
MessageBox -> (“Devam edilsin mi?”,”son adım”,
MessageBoxButtons.YesNo,MessageBoxIcon.Question);
DialogResult islem = MessageBox -> (“Devam edilsin mi?”,”son adım”,
MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(islem==WindowsFormDialogResult.Yes)
{
MessageBox.Show (“Kayıt tamamlandı”,”bilgilendirme”,
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show (“Kayıdınız gerçekleşmedi”,”bilgilendirme”,
MessageBoxButtons.OK,MessageBoxIcon.Error);
}
• Button7(text->mesaj_7)
– Click event:
DialogResult islem = MessageBox -> (“Devam edilsin mi?”,”son adım”,
MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if(islem==WindowsFormDialogResult.OK)
{
MessageBox.Show (“Kayıt tamamlandı”,”bilgilendirme”,
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show (“Kayıt yapmadan çık”,”bilgilendirme”,
MessageBoxButtons.OK,MessageBoxIcon.Error);
}
Örnek
Label1(text->kullanıcı adı)
Label2(text->şifre)
Button1(text->Giriş)
Button2(text->İptal)
• private void button1_click(…)
{
if(TextBox1.Text!=“ “)
{
if(TextBox2.Text==“ ”)
{
MessageBox.Show(“Şifre Giriniz”);
}
else
{
MessageBox.Show(“Giriş Onaylandı”);
}
}
else
{
MessageBox.Show(“Kullanıcı Girilmedi”);
}
}
• private void button2_click(…)
{
this.Close();
}
• private void button1_click(…)
{
if(TextBox1.Text!=“ “ & TextBox2.Text!=“ ”))
{
if(TextBox1.Text==“admin” & TextBox2.Text==“1234”)
{
MessageBox.Show(“Giriş Onaylandı”);
}
else
{
MessageBox.Show(“Giriş Hatalı”);
}
}
else
{
MessageBox.Show(“Kullanıcı ve Şifre Girilmedi”);
}
}
Yeni Form ekleme
• private void button1_click(…)
{
if(TextBox1.Text!=“ “ & TextBox2.Text!=“ ”))
{
if(TextBox1.Text==“admin” & TextBox2.Text==“1234”)
{
Form2 YeniForm =new Form2();
YeniForm.Show();
}
else
{
MessageBox.Show(“Giriş Hatalı”);
}
}
else
{
MessageBox.Show(“Kullanıcı ve Şifre Girilmedi”);
}
}
Örnek:Dizi Tanımlama
• Button_click:
string[] hafta=new string[7];
hafta[0]=“Pazartesi”;
hafta[1]=“Salı”;
…
MessageBox.Show(hafta[2]);
Ya da
string[] hafta=new string[7] {Pazartesi, Salı,….}
string[] hafta= {Pazartesi, Salı,….}
şeklinde tanımlama yapılabilir.
Örnek: Dizi
• Button_click:
int[] dizi=new int[] {1, 2, 3, 4};
this.Text=dizi[2].toString();
Örnek: Dizi
• Butona basıldığında dizi elemanları listBox’a eklenecek
Sayıların her adımda toplamı yazdırılacak
int[] dizi={1, 2, 3, 4};
int i=0;
int curr=0;
Button_click{
if(i<dizi.length){
listBox1.Items.Add(dizi[i]);
curr +=dizi[i];
this.Text=“Toplam=“ + curr;
i=i+1;
}
if(i==dizi.length)
button1.Enabled=false;
TextBox
MessageBox.Show(Convert.ToString(c));
ListBox
private void button1_Click(object sender, EventArgs e)
{
string a;
a = Convert.ToString(textBox1.Text);
listBox1.Items.Add(a);
}
private void button2_Click(object sender, EventArgs
e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
string a;
a = Convert.ToString(textBox1.Text);
listBox1.Items.Add(a);
int gelen = listBox1.Items.Count;
this.Text = gelen.ToString();
}