• 大小: 13.18MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-08
  • 语言: C#
  • 标签: C#  钢琴  源码  

资源简介

初学C#,个人编写小程序,点击键盘会出现图片,声音还可以,可以满足一般的演奏要求。对初学者有一定参考价值。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;


namespace WindowsApplication1
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            pictureBoxphoto.Visible = false;
            this.pictureBoxpt.Image = Properties.Resources.photo1;
            dev.SetCooperativeLevel(this Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            
            
        }
        private Microsoft.DirectX.DirectSound.Device dev = new Microsoft.DirectX.DirectSound.Device();
        private string fpath;
      //发声函数/////////////////////////////////
        private void playsound(string path)
        {
            fpath = Application.StartupPath + “\\sound\\“+path+“.wav“;            
            try
            {
                Microsoft.DirectX.DirectSound.SecondaryBuffer snd = new Microsoft.DirectX.DirectSound.SecondaryBuffer(fpath dev);
                snd.Play(0 Microsoft.DirectX.DirectSound.BufferPlayFlags.Default);
                fpath = null;
            }
            catch (Exception ex)
            {
                label1.Text = ex.ToString();
            } 
        
        
        }

//按下键响应////////////////////////

        private void Form1_KeyDown(object sender KeyEventArgs e)
        {

            if (e.KeyCode == Keys.Q && q == 1)
            {
                //下方的黑白键盘更换图片
                this.pictureBox_k.Image = Image.FromFile(Application.StartupPath + “\\picture\\WhiteKey222.PNG“);
                //键盘上按键的图片更换
                this.pictureBoxq.Image = Properties.Resources.k;
                //显示大照片,使得picturebox显示
                pictureBoxphoto.Visible = true;
                //让picturebox显示大照片
                this.pictureBoxphoto.Image = Properties.Resources.k;
                //设置标志位,当按下一个键之后只能响应一次
                q = 0;
                //播放声音
                playsound(“15“);
                
            }
            if (e.KeyCode == Keys.W && w == 1)
            {
                
                this.pictureBox_l.Image = Image.FromFile(Application.StartupPath + “\\picture\\WhiteKey222.PNG“);
                this.pictureBoxw.Image = Properties.Resources.l;
                pictureBoxphoto.Visible = true;
                this.pictureBoxphoto.Image = Properties.Resources.l;
                w = 0;
                playsound(“16“);
                
            }
            if (e.KeyCode == Keys.E && keye == 1)
            {
                
                this.pictureBox_e.Image = Image.FromFile(Application.StartupPath + “\\picture\\BlackKeyPressed22.PNG“);
                this.pictureBoxe.Image = Properties.Resources.e;
                pictureBoxphoto.Visible = true;
                this.pictureBoxp

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1422  2009-11-22 21:55  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\1++.bmp

     文件       1498  2009-11-22 21:53  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\1+.bmp

     文件       1802  2009-11-22 21:40  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\1--.bmp

     文件       1422  2009-11-22 21:48  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\1-.bmp

     文件       1422  2009-11-22 21:51  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\1.bmp

     文件       1422  2009-11-22 21:55  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\2++.bmp

     文件       1270  2009-11-22 21:53  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\2+.bmp

     文件       1498  2009-11-22 21:45  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\2--.bmp

     文件       1422  2009-11-22 21:50  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\2-.bmp

     文件       1566  2009-11-22 21:52  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\2.bmp

     文件       1498  2009-11-22 21:56  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\3++.bmp

     文件       1422  2009-11-22 21:53  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\3+.bmp

     文件       1710  2009-11-22 21:46  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\3--.bmp

     文件       1414  2009-11-22 21:50  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\3-.bmp

     文件       1550  2009-11-22 21:52  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\3.bmp

     文件       1818  2009-11-22 21:56  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\4++.bmp

     文件       1494  2009-11-22 21:53  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\4+.bmp

     文件       1422  2009-11-22 21:47  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\4--.bmp

     文件       1482  2009-11-22 21:50  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\4-.bmp

     文件       1350  2009-11-22 21:52  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\4.bmp

     文件       1638  2009-11-22 21:56  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\5++.bmp

     文件       1566  2009-11-22 21:54  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\5+.bmp

     文件       1482  2009-11-22 21:47  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\5--.bmp

     文件       1350  2009-11-22 21:51  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\5-.bmp

     文件       1494  2009-11-22 21:52  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\5.bmp

     文件       1494  2009-11-22 21:57  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\6++.bmp

     文件       1494  2009-11-22 21:54  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\6+.bmp

     文件       1638  2009-11-22 21:48  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\6--.bmp

     文件       1654  2009-11-22 21:51  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\6-.bmp

     文件       1638  2009-11-22 21:52  WindowsApplication1\WindowsApplication1\bin\Debug\Picture\6.bmp

............此处省略215个文件信息

评论

共有 条评论