From 2fda337efb8cf13f13b38dda00b2434431216d4c Mon Sep 17 00:00:00 2001 From: milimoe Date: Tue, 21 Nov 2023 20:51:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Desktop/Program.cs | 2 +- ...m1.Designer.cs => ChessBoardExample.Designer.cs} | 2 +- .../Solutions/{Form1.cs => ChessBoardExample.cs} | 13 ++++++++----- .../{Form1.resx => ChessBoardExample.resx} | 0 4 files changed, 10 insertions(+), 7 deletions(-) rename Desktop/Solutions/{Form1.Designer.cs => ChessBoardExample.Designer.cs} (96%) rename Desktop/Solutions/{Form1.cs => ChessBoardExample.cs} (92%) rename Desktop/Solutions/{Form1.resx => ChessBoardExample.resx} (100%) diff --git a/Desktop/Program.cs b/Desktop/Program.cs index 3ac3c77..6105b88 100644 --- a/Desktop/Program.cs +++ b/Desktop/Program.cs @@ -11,7 +11,7 @@ namespace Desktop // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new ChessBoardExample.Form1()); + Application.Run(new ChessBoardExample.ChessBoardExample()); } } } \ No newline at end of file diff --git a/Desktop/Solutions/Form1.Designer.cs b/Desktop/Solutions/ChessBoardExample.Designer.cs similarity index 96% rename from Desktop/Solutions/Form1.Designer.cs rename to Desktop/Solutions/ChessBoardExample.Designer.cs index a9185e9..f2e4391 100644 --- a/Desktop/Solutions/Form1.Designer.cs +++ b/Desktop/Solutions/ChessBoardExample.Designer.cs @@ -1,6 +1,6 @@ namespace ChessBoardExample { - partial class Form1 + partial class ChessBoardExample { /// /// Required designer variable. diff --git a/Desktop/Solutions/Form1.cs b/Desktop/Solutions/ChessBoardExample.cs similarity index 92% rename from Desktop/Solutions/Form1.cs rename to Desktop/Solutions/ChessBoardExample.cs index 2167823..af1640c 100644 --- a/Desktop/Solutions/Form1.cs +++ b/Desktop/Solutions/ChessBoardExample.cs @@ -1,14 +1,14 @@ namespace ChessBoardExample { - public partial class Form1 : Form + public partial class ChessBoardExample : Form { - const int gridSize = 12; // 每个小方块大小为40像素 + const int gridSize = 32; // 每个小方块大小为40像素 const int step = 3; // 递进 Dictionary chessboardDict = new Dictionary(); HashSet redPanelsSet = new HashSet(); - public Form1() + public ChessBoardExample() { InitializeComponent(); InitializeChessboard(); @@ -29,6 +29,8 @@ if (redPanelsSet.Count > 0) SetOriginalCells(); else CheckRedCells(5, 9); }); + + Size = new Size(562, 562); } private void InitializeChessboard() @@ -128,10 +130,11 @@ } } - private void OnCellMouseEnter(object sender, System.EventArgs e) + private void OnCellMouseEnter(object? sender, System.EventArgs e) { try { + if (sender is null) return; // 获取当前鼠标进入区域对应格子位置; string[] s = ((Panel)sender).Name.Split('_'); int x = int.Parse(s[0]); @@ -145,7 +148,7 @@ } } - private void OnCellMouseLeave(object sender, EventArgs e) + private void OnCellMouseLeave(object? sender, EventArgs e) { SetOriginalCells(); } diff --git a/Desktop/Solutions/Form1.resx b/Desktop/Solutions/ChessBoardExample.resx similarity index 100% rename from Desktop/Solutions/Form1.resx rename to Desktop/Solutions/ChessBoardExample.resx