C#日语五十音图改进遍历数组

版权声明: https://blog.csdn.net/eds124/article/details/82794477
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.Media;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Location = new Point(0, 0);
            this.Size = new Size(515, 835);
            this.MaximizeBox = false;

            Button[,] blist = new Button[16, 5];
            string[,] list = {
            { "あア", "いイ", "うウ", "えエ", "おオ" }, 
            { "かカ", "きキ", "くク", "けケ", "こコ" },
            { "がガ", "ぎギ", "ぐグ", "げゲ", "ごゴ" },
            { "さサ", "しシ", "すス", "せセ", "そソ" },
            { "ざザ", "じジ", "ずズ", "ぜゼ", "ぞゾ" }, 
            { "たタ", "ちチ", "つツ", "てテ", "とト" },
            { "だダ", "ぢヂ", "づヅ", "でデ", "どド" },
            { "なナ", "にニ", "ぬヌ", "ねネ", "のノ" },
            { "はハ", "ひヒ", "ふフ", "へヘ", "ほホ" }, 
            { "ばバ", "びビ", "ぶブ", "べベ", "ぼボ" }, 
            { "ぱパ", "ぴピ", "ぷプ", "ぺペ", "ぽポ" }, 
            { "まマ", "みミ", "むム", "めメ", "もモ" }, 
            { "やヤ", "いイ", "ゆユ", "えエ", "よヨ" }, 
            { "らラ", "りリ", "るル", "れレ", "ろロ" }, 
            { "わワ", "いイ", "うウ", "えエ", "をヲ" }, 
            { "んン", null, null, null, null}
        };
            
            for (int i = 0; i < list.GetLength(0); i++)
            {
                for (int j = 0; j < list.GetLength(1); j++)
                {
                    if (list[i, j] == null)
                    {
                        break;
                    }
                    blist[i, j] = new Button();
                    blist[i, j].Text = list[i, j];
                    blist[i, j].Location = new Point(j * 100, i * 50);
                    blist[i, j].Size = new Size(100, 50);
                    blist[i, j].Font = new Font("微软雅黑", 20);
                    this.Controls.Add(blist[i, j]);
                    blist[i, j].Click += new EventHandler(this.button_click);
                }
            }

        }

        private void button_click(object sender, EventArgs ea)
        {
            string b_name = ((Button)sender).Text;
            try
            {
                using (SoundPlayer sp = new SoundPlayer("read/" + b_name + ".wav"))
                {
                    sp.Load();
                    sp.Play();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/eds124/article/details/82794477