public MazeGuiView(Maze maze) { Init(maze); }
void Init(Maze maze) { this.maze = maze; this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.MouseClick += new MouseEventHandler(MazeGuiPanel_MouseClick); this.Paint += new PaintEventHandler(MazeGuiPanel_paint); //this.MouseMove += new MouseEventHandler(MazeGuiPanel_Move); this.SetStyle(ControlStyles.ResizeRedraw, true); // redraw everything when resizing }
void openMenuItem_OnClick(Object sender, EventArgs e) { if (!checkSaved()) return; OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Float Open Map"; dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; dlg.InitialDirectory = Environment.CurrentDirectory; if (dlg.ShowDialog() == DialogResult.OK) { string file = dlg.FileName; System.Console.WriteLine("file:" + file); try { Maze mz = new Maze(file); mazeGuiView.Maze = mz; } catch (FileLoadException ex) { MessageBox.Show(this, "There was a FileLoadException, whatever that is. (" + ex.Message + ")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //System.Console.WriteLine("File load exception."); } catch (FileNotFoundException ex) { MessageBox.Show(this, "File not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); System.Console.Error.WriteLine("ERROR: " + ex.Message); //System.Console.WriteLine("File not found."); } catch (MazeException ex) { MessageBox.Show(this, "Couldn't read maze file " + file + ", error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }