public MusicKeyboard() : base() { timer1 = new Timer(); MusKey mk; BlackMusKey bmk; KeyBoardEntries ke; int[] whitePitch = { 1, 3, 5, 6, 8, 10, 12, 13, 15, 17, 18, 20, 22, 24 }; for (int k = 0; k < whitePitch.Length; k++) { int pitch = whitePitch[k]; int xPos = k * 20; mk = new MusKey(pitch, xPos, 20); ke = new KeyBoardEntries(timer1, count, xLoc, yLoc); mk.MouseDown += new MouseEventHandler(this.button1_MouseDown); mk.MouseUp += new MouseEventHandler(this.button1_MouseUp); mk.KeyDown += new KeyEventHandler(ke.button1_KeyDown); mk.KeyUp += new KeyEventHandler(ke.button1_KeyUp); this.Controls.Add(mk); } int[] blackPitch = { 2, 4, 7, 9, 11, 14, 16, 19, 21, 23 }; int[] xPosArray = { 10, 30, 70, 90, 110, 150, 170, 210, 230, 250 }; for (int k = 0; k < blackPitch.Length; k++) { int pitch = blackPitch[k]; int xPos = xPosArray[k]; bmk = new BlackMusKey(pitch, xPos, 20); bmk.MouseDown += new MouseEventHandler(this.button1_MouseDown); bmk.MouseUp += new MouseEventHandler(this.button1_MouseUp); this.Controls.Add(bmk); this.Controls[this.Controls.Count - 1].BringToFront(); } }
private void button1_MouseDown(object sender, MouseEventArgs e) { String folderpath = "C:\\Users\\Ezek_\\source\\repos\\lakbarmazzataghawdex2\\Notes-Sound files"; sp = new SoundPlayer(); foreach (Object obj in this.Controls) { // if(obj.GetType() =MusKey.getType()) // { // } MusKey mk = new MusKey(); if (sender == mk) { if (e.Button == MouseButtons.Left) { timer1.Enabled = true; count = 0; timer1.Start(); sp.SoundLocation = folderpath + mk.MusicNote.ToString() + ".wav"; sp.Play(); } } } }