Esempio n. 1
0
 private void _gen_Click(object sender, EventArgs e)
 {
     try
     {
         int           width  = Convert.ToInt32(w.Text);
         int           height = Convert.ToInt32(h.Text);
         int           size   = 2;
         MazeGenerator mg     = new MazeGenerator(width, height);
         mg.Generator();
         this.pictureBox1.Image = mg._result(size);
     }
     catch (InvalidCastException)
     {
         MessageBox.Show("請輸入數字", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch
     {
         MessageBox.Show("有地方出錯了", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title  = "save Maze File";
            sfd.Filter = "jpg Files(*.jpg)|*.jpg|png Files(*.png)|*.png";

            if (this.pictureBox1.Image != null)
            {
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    if ((sfd.FileName) != string.Empty)
                    {
                        pictureBox1.Image.Save(sfd.FileName);
                    }
                }
            }
            else
            {
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    if ((sfd.FileName) != string.Empty)
                    {
                        try
                        {
                            int           width  = Convert.ToInt32(w.Text);
                            int           height = Convert.ToInt32(h.Text);
                            int           size   = 2;
                            MazeGenerator mg     = new MazeGenerator(width, height);
                            mg.Generator();
                            mg._result(size).Save(sfd.FileName);
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }