MVC model view controller a c# tan geçiş hakkında makalemi çok kısa bir süre sonra buraya yazacağım.
Buradan indirebilirsiniz
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 WindowsFormsApplication11 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Button btn,btn1; int puan = 10; private void dogrumu(Button parButton) { if (btn1 != null) { btn.Text = "#"; btn1.Text = "#"; btn = null; btn1 = null; if(puan!=0) puan = puan - 1; } if (btn == null || btn==parButton) { btn = parButton; parButton.Text = parButton.Tag.ToString(); } else { parButton.Text = parButton.Tag.ToString(); if (parButton.Text == btn.Text) { btn.Enabled = false; parButton.Enabled = false; btn1 = null; btn = null; label2.Text = Convert.ToString(puan + Convert.ToInt32(label2.Text)); puan = 10; } else { parButton.Text = parButton.Tag.ToString(); btn1 = parButton; } } } private void button1_Click(object sender, EventArgs e) { dogrumu(button1); } private void button7_Click(object sender, EventArgs e) { dogrumu(button7); } private void button2_Click(object sender, EventArgs e) { dogrumu(button2); } private void button8_Click(object sender, EventArgs e) { dogrumu(button8); } private void button3_Click(object sender, EventArgs e) { dogrumu(button3); } private void button4_Click(object sender, EventArgs e) { dogrumu(button4); } private void button5_Click(object sender, EventArgs e) { dogrumu(button5); } private void button6_Click(object sender, EventArgs e) { dogrumu(button6); } private void button9_Click(object sender, EventArgs e) { dogrumu(button9); } private void button12_Click(object sender, EventArgs e) { dogrumu(button12); } private void button11_Click(object sender, EventArgs e) { dogrumu(button11); } private void button10_Click(object sender, EventArgs e) { dogrumu(button10); } private void Form1_Load(object sender, EventArgs e) { } private void button16_Click(object sender, EventArgs e) { } private void Form1_Load_1(object sender, EventArgs e) { int[] sayi = new int[16]; Random r = new Random(); int sayac = 0; int rastgele = 0; while (sayac < 16) { rastgele = r.Next(1, 17); if (Array.IndexOf(sayi, rastgele) == -1) { sayi[sayac++] = rastgele; } } for (int i = 0; i < 16; i++) { if (sayi[i] > 8) sayi[i] = sayi[i] - 8; } int sayim = 0; foreach (Control c in this.Controls) { if (c is Button) { ((Button)c).Tag = sayi[sayim].ToString(); sayim++; } } } private void button13_Click(object sender, EventArgs e) { dogrumu(button13); } private void button14_Click(object sender, EventArgs e) { dogrumu(button14); } private void button15_Click(object sender, EventArgs e) { dogrumu(button15); } private void button16_Click_1(object sender, EventArgs e) { dogrumu(button16); } private void label3_Click(object sender, EventArgs e) { int[] sayi = new int[16]; Random r = new Random(); int sayac = 0; int rastgele = 0; while (sayac < 16) { rastgele = r.Next(1, 17); if (Array.IndexOf(sayi, rastgele) == -1) { sayi[sayac++] = rastgele; } } for (int i = 0; i < 16; i++) { if (sayi[i] > 8) sayi[i] = sayi[i] - 8; } int sayim = 0; foreach (Control c in this.Controls) { if (c is Button) { ((Button)c).Tag = sayi[sayim].ToString(); ((Button)c).Text = "#"; ((Button)c).Enabled = true; sayim++; } } label2.Text = "0"; puan = 10; } } }
ilk olarak using e using System.IO; using System.Runtime.InteropServices; ekliyoruz.
using System.IO; using System.Runtime.InteropServices;
daha sonra class’ın içerisinde aşağıdaki tanımaları yapıyorsunuz. [DllImport("winmm.dll")] private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); public string Pcommand; public bool isOpen;
[DllImport("winmm.dll")] private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); public string Pcommand; public bool isOpen;
bir buton ve bir adet openFileDialog ekliyorsunuz. Butonun adını Dosya Aç yada Dosya Seç yapabilirsiniz.
Butonun Click Event’ına openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*.mp3;*.mpg;*.dat;*.avi;*.wmv"; openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "") textBox1.Text = openFileDialog1.FileName; yazıyoruz.
openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*.mp3;*.mpg;*.dat;*.avi;*.wmv"; openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "") textBox1.Text = openFileDialog1.FileName;
Bir button daha ekleyip text özelliğine play yada çal yazıyoruz click eventına Pcommand = "open \"" + textBox1.Text + "\" type mpegvideo alias MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = true; Play(true);
Pcommand = "open \"" + textBox1.Text + "\" type mpegvideo alias MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = true; Play(true);
yazıyoruz.
durdur butonuna aşağıdaki kodları Pcommand = "close MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = false;
Pcommand = "close MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = false;
Çıkış butonuna da aşağıdaki kodları yazıyorsunuz. Application.Exit();
Application.Exit();
en son aşağıdaki metotu da ekleyince mp3lerimizi çalabiliriz. public void Play(bool loop) { if (isOpen) { Pcommand = "play MediaFile"; if (loop) Pcommand += " REPEAT"; mciSendString(Pcommand, null, 0, IntPtr.Zero); } }
public void Play(bool loop) { if (isOpen) { Pcommand = "play MediaFile"; if (loop) Pcommand += " REPEAT"; mciSendString(Pcommand, null, 0, IntPtr.Zero); } }
Aşağıda çalışan örneğin tam kodları var. 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.IO; using System.Runtime.InteropServices; namespace WindowsFormsApplication99 { public partial class Form1 : Form { [DllImport("winmm.dll")] private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); public string Pcommand; public bool isOpen; public Form1() { InitializeComponent(); } private void DosyaAc_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*.mp3;*.mpg;*.dat;*.avi;*.wmv"; openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "") textBox1.Text = openFileDialog1.FileName; } private void DosyaCal_Click(object sender, EventArgs e) { Pcommand = "open \"" + textBox1.Text + "\" type mpegvideo alias MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = true; Play(true); } private void Durdur_Click(object sender, EventArgs e) { Pcommand = "close MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = false; } private void Cikis_Click(object sender, EventArgs e) { Application.Exit(); } public void Play(bool loop) { if (isOpen) { Pcommand = "play MediaFile"; if (loop) Pcommand += " REPEAT"; mciSendString(Pcommand, null, 0, IntPtr.Zero); } } } }
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.IO; using System.Runtime.InteropServices; namespace WindowsFormsApplication99 { public partial class Form1 : Form { [DllImport("winmm.dll")] private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); public string Pcommand; public bool isOpen; public Form1() { InitializeComponent(); } private void DosyaAc_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*.mp3;*.mpg;*.dat;*.avi;*.wmv"; openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "") textBox1.Text = openFileDialog1.FileName; } private void DosyaCal_Click(object sender, EventArgs e) { Pcommand = "open \"" + textBox1.Text + "\" type mpegvideo alias MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = true; Play(true); } private void Durdur_Click(object sender, EventArgs e) { Pcommand = "close MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = false; } private void Cikis_Click(object sender, EventArgs e) { Application.Exit(); } public void Play(bool loop) { if (isOpen) { Pcommand = "play MediaFile"; if (loop) Pcommand += " REPEAT"; mciSendString(Pcommand, null, 0, IntPtr.Zero); } } } }
Random sayi = new Random(); int no = sayi.Next(1,11); button1.Text = no.ToString();
üst teki kod 1 den 10 a kadar olan sayıalrı seçer yani gelme ihtimali olan sayılar 1-2-3-4-5-6-7-8-9-10 dur. 11 seçilmez. Random sınıfının Next metodu sayı seçmemizi sağlar. Forma bir button ekleyip buttona kodu yazın button un text özelliği değişecektir.