public MainForm() { const int LAYOUT_COLUMN_COUNT = 4; const int LAYOUT_ROW_COUNT = 4; const int ZERO = 0; const int ONE = 1; const int TWO = 2; const int THREE = 3; InitializeComponent(); // // prepare presentation model, model // _model = new DrawingModel.Model(); _presentationModel = new PresentationModel.PresentationModel(_model); _model._modelChanged += HandleModelChanged; _serializer = new Serializer(); // // _mainLayout // TableLayoutPanel mainLayout = new TableLayoutPanel(); mainLayout.ColumnCount = LAYOUT_COLUMN_COUNT; mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F)); mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F)); mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F)); mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F)); mainLayout.RowCount = LAYOUT_ROW_COUNT; mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F)); mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F)); mainLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F)); mainLayout.Dock = DockStyle.Fill; Controls.Add(mainLayout); // // prepare line button // mainLayout.Controls.Add(_line, ZERO, ZERO); _line.Enabled = false; _line.Text = "Line"; _line.Dock = DockStyle.Fill; _line.AutoSize = true; _line.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _line.Click += HandleLineButtonClick; // // prepare rectangle button // mainLayout.Controls.Add(_rectangle, ONE, ZERO); _rectangle.Text = "Rectangle"; _rectangle.Dock = DockStyle.Fill; _rectangle.AutoSize = true; _rectangle.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _rectangle.Click += HandleRectangleButtonClick; // // prepare rectangle button // mainLayout.Controls.Add(_ellipse, TWO, ZERO); _ellipse.Text = "Ellipse"; _ellipse.Dock = DockStyle.Fill; _ellipse.AutoSize = true; _ellipse.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _ellipse.Click += HandleEllipseButtonClick; // // prepare arrow button // mainLayout.Controls.Add(_arrow, THREE, ZERO); _arrow.Text = "Arrow"; _arrow.Dock = DockStyle.Fill; _arrow.AutoSize = true; _arrow.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _arrow.Click += HandleArrowButtonClick; // // prepare delete button // mainLayout.Controls.Add(_delete, ZERO, ONE); _delete.Enabled = _presentationModel.IsClearButtonEnabled; _delete.Text = "Delete"; _delete.Dock = DockStyle.Fill; _delete.AutoSize = true; _delete.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _delete.Click += HandleDeleteButtonClick; // // prepare clear button // mainLayout.Controls.Add(_clear, ONE, ONE); _clear.Enabled = _presentationModel.IsClearButtonEnabled; _clear.Text = "Clear"; _clear.Dock = DockStyle.Fill; _clear.AutoSize = true; _clear.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _clear.Click += HandleClearButtonClick; // // prepare undo button // mainLayout.Controls.Add(_undo, TWO, ONE); _undo.Enabled = false; _undo.Text = "Undo"; _undo.Dock = DockStyle.Fill; _undo.AutoSize = true; _undo.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _undo.Click += HandleUndoButtonClick; // // prepare redo button // mainLayout.Controls.Add(_redo, THREE, ONE); _redo.Enabled = false; _redo.Text = "Redo"; _redo.Dock = DockStyle.Fill; _redo.AutoSize = true; _redo.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _redo.Click += HandleRedoButtonClick; // // prepare canvas // mainLayout.Controls.Add(_canvas, ZERO, TWO); mainLayout.SetColumnSpan(_canvas, LAYOUT_COLUMN_COUNT); _canvas.Dock = DockStyle.Fill; _canvas.BackColor = System.Drawing.Color.LightYellow; _canvas.MouseDown += HandleCanvasPressed; _canvas.MouseUp += HandleCanvasReleased; _canvas.MouseMove += HandleCanvasMoved; _canvas.Paint += HandleCanvasPaint; // // prepare upload button // mainLayout.Controls.Add(_upload, ZERO, THREE); mainLayout.SetColumnSpan(_upload, LAYOUT_COLUMN_COUNT); _upload.Enabled = _presentationModel.IsClearButtonEnabled; _upload.Text = "Upload"; _upload.Dock = DockStyle.Fill; _upload.AutoSize = true; _upload.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; _upload.Click += HandleUploadButtonClick; // //reload saved file // _model.SetShapes(_serializer.ReadShapes()); }