private void loadButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Map Files (.map)|*.map"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = false; DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. { loadname.Text = openFileDialog1.FileName; SaveandLoad sv = new SaveandLoad(); map = sv.Deserialize(openFileDialog1.FileName); if (map != null) { pawn_x.Value = map.pawn.posx; pawn_y.Value = map.pawn.posy; finish_x.Value = map.finish.posx; finish_y.Value = map.finish.posy; width.Value = map.mapwidth; height.Value = map.mapheight; pawn = map.pawn; finish = map.finish; //mazebound = new PictureBox[map.mapheight, map.mapwidth]; this.pawn = map.pawn; this.finish = map.finish; reset(); this.Refresh(); mazebound = new PictureBox[map.mapheight, map.mapwidth]; getBlankMazeInterface(); enablePawn(groupBox2, pawn_x, pawn_y, width, height); enablePawn(groupBox4, finish_x, finish_y, width, height); } else { MessageBox.Show("Maaf, terjadi kesalahan!"); } } Console.WriteLine(result); // <-- For debugging use. }
private void saveButton_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Map Files (.map)|*.map"; saveFileDialog1.Title = "Save your map"; saveFileDialog1.ShowDialog(); // If the file name is not an empty string open it for saving. if (saveFileDialog1.FileName != "") { map.pawn = this.pawn; map.finish = this.finish; map.setMazeDesign(mazebound); map.mapheight = height_temp; map.mapwidth = width_temp; savename.Text = saveFileDialog1.FileName; SaveandLoad sv = new SaveandLoad(); sv.Serialize(map, saveFileDialog1.FileName); } }