using ChessPanel; using System; using System.Windows.Forms; namespace Chess { public class ChessGame : Panel { ChessBoard board; public ChessGame() { InitializeComponent(); RefreshSize(); } private void InitializeComponent() { this.board = new ChessBoard(); this.SuspendLayout(); // // board // this.board.GridSize = 8; this.board.Cursor = Cursors.Hand; this.board.Location = new System.Drawing.Point(0, 0); this.board.Name = "board"; int size = Math.Min(this.Size.Width, this.Size.Height); board.Size = new System.Drawing.Size(size, size); this.board.TabIndex = 0; // // ChessGame // this.Controls.Add(this.board); this.Resize += new System.EventHandler(this.ResizeEvent); this.ResumeLayout(false); } private void ResizeEvent(object sender, EventArgs e) { RefreshSize(); } internal void FormClosing(object sender, FormClosingEventArgs e) { if (board.isSaved) { e.Cancel = false; } else { switch (MessageBox.Show("Das aktuelle Spiel ist noch nicht gespeichert!\nMöchtest du es jetzt speichern?", "Speichern?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation)) { case DialogResult.Cancel: e.Cancel = true; break; case DialogResult.Yes: SaveGame(); e.Cancel = false; break; case DialogResult.No: e.Cancel = false; break; default: break; } } } private void SaveGame() { MessageBox.Show("TODO: SaveGame here!"); } private void RefreshSize() { int size = Math.Min(this.Size.Width, this.Size.Height); board.Size = new System.Drawing.Size(size, size); board.Location = this.Size.Width > this.Size.Height ? new System.Drawing.Point((this.Size.Width - size) / 2, 0) : new System.Drawing.Point(0, (this.Size.Height - size) / 2); } } }