From 532909ed1adec35bf94285bab586320ed454a344 Mon Sep 17 00:00:00 2001 From: jie65535 <840465812@qq.com> Date: Fri, 15 Jan 2021 22:25:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E9=87=8D=E7=BB=98?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E5=87=8F=E5=B0=91=E9=87=8D=E7=BB=98?= =?UTF-8?q?=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeMatrix/Properties/AssemblyInfo.cs | 2 +- CodeMatrix/UCCodeMatrix.cs | 97 +++++++++++++-------------- 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/CodeMatrix/Properties/AssemblyInfo.cs b/CodeMatrix/Properties/AssemblyInfo.cs index 7aedafd..cec2aa3 100644 --- a/CodeMatrix/Properties/AssemblyInfo.cs +++ b/CodeMatrix/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("CodeMatrix")] -[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyCopyright("© 2020 jie65535@github.com")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/CodeMatrix/UCCodeMatrix.cs b/CodeMatrix/UCCodeMatrix.cs index 66320ee..b582c6f 100644 --- a/CodeMatrix/UCCodeMatrix.cs +++ b/CodeMatrix/UCCodeMatrix.cs @@ -14,7 +14,8 @@ namespace CodeMatrix public int Rows { get; set; } public byte[,] Matrix { get; set; } public Point SelectPoint { get; private set; } - public Point CursorPosition { get; private set; } + public Point CursorPoint { get; private set; } + public Point HoverPoint { get; private set; } public RectangleF CodeMatrixRect { get; private set; } /// @@ -43,10 +44,11 @@ namespace CodeMatrix private void InitData() { - Rows = 5; - Columns = 5; + Rows = 9; + Columns = 16; CellSize = new SizeF(40, 40); _currDir = Directions.Horizontal; + HoverPoint = new Point(-1, -1); } private void InitComponent() @@ -84,9 +86,11 @@ namespace CodeMatrix CodeMatrixRect = new RectangleF(blockOffset, blockSize); } + //int _paintCount; protected override void OnPaint(PaintEventArgs e) { if (!_IsLoaded) return; + //_paintCount++; var offset = new PointF(SelectPoint.X*CellSize.Width, SelectPoint.Y*CellSize.Height); if (_currDir == Directions.Horizontal) @@ -94,35 +98,28 @@ namespace CodeMatrix else if (_currDir == Directions.Vertical) e.Graphics.FillRectangle(Styles.Default.DefaultLineBackColor, offset.X + CodeMatrixRect.X, 0, CellSize.Width, Height); - Cursor = Cursors.Default; - if (CursorPosition.X >= 0 && Matrix[CursorPosition.X, CursorPosition.Y] != 0) + if (HoverPoint.X >= 0) { + Cursor = Cursors.Hand; if (_currDir == Directions.Horizontal) { - if (CursorPosition.Y == SelectPoint.Y) - { - offset.X = CursorPosition.X * CellSize.Width; - e.Graphics.FillRectangle(Styles.Default.SelectLineBackColor, offset.X + CodeMatrixRect.X, 0, CellSize.Width, Height); - Cursor = Cursors.Hand; - } + offset.X = HoverPoint.X * CellSize.Width; + e.Graphics.FillRectangle(Styles.Default.SelectLineBackColor, offset.X + CodeMatrixRect.X, 0, CellSize.Width, Height); } else if (_currDir == Directions.Vertical) { - if (CursorPosition.X == SelectPoint.X) - { - offset.Y = CursorPosition.Y * CellSize.Height; - e.Graphics.FillRectangle(Styles.Default.SelectLineBackColor, 0, offset.Y + CodeMatrixRect.Y, Width, CellSize.Height); - Cursor = Cursors.Hand; - } + offset.Y = HoverPoint.Y * CellSize.Height; + e.Graphics.FillRectangle(Styles.Default.SelectLineBackColor, 0, offset.Y + CodeMatrixRect.Y, Width, CellSize.Height); } - if (Cursor == Cursors.Hand) - { - offset.X += CodeMatrixRect.X; - offset.Y += CodeMatrixRect.Y; - e.Graphics.DrawRectangle(Styles.Default.SelectCellBorderPen, offset.X, offset.Y, CellSize.Width - 1, CellSize.Height - 1); - e.Graphics.DrawRectangle(Styles.Default.SelectCellBorderPen, offset.X + 4, offset.Y + 4, CellSize.Width - 8 - 1, CellSize.Height - 8 - 1); - } + offset.X += CodeMatrixRect.X; + offset.Y += CodeMatrixRect.Y; + e.Graphics.DrawRectangle(Styles.Default.SelectCellBorderPen, offset.X, offset.Y, CellSize.Width - 1, CellSize.Height - 1); + e.Graphics.DrawRectangle(Styles.Default.SelectCellBorderPen, offset.X + 4, offset.Y + 4, CellSize.Width - 8 - 1, CellSize.Height - 8 - 1); + } + else + { + Cursor = Cursors.Default; } for (int col = 0; col < Columns; col++) @@ -149,6 +146,8 @@ namespace CodeMatrix e.Graphics.DrawString(code, Font, brush, codePoint); } } + + //e.Graphics.DrawString(_paintCount.ToString(), Font, Styles.Default.CodeBrush, 0, 0); } protected override void OnMouseMove(MouseEventArgs e) @@ -160,17 +159,30 @@ namespace CodeMatrix { var offset = new PointF(e.X-CodeMatrixRect.X, e.Y-CodeMatrixRect.Y); var current = new Point((int)(offset.X / CellSize.Width), (int)(offset.Y / CellSize.Height)); - if (CursorPosition != current) + if (CursorPoint != current) { - CursorPosition = current; - Invalidate(); + CursorPoint = current; + var hoverPoint = new Point(-1, -1); + if (Matrix[CursorPoint.X, CursorPoint.Y] != 0) + { + if (_currDir == Directions.Horizontal && CursorPoint.Y == SelectPoint.Y) + hoverPoint = CursorPoint; + else if (_currDir == Directions.Vertical && CursorPoint.X == SelectPoint.X) + hoverPoint = CursorPoint; + } + if (HoverPoint != hoverPoint) + { + HoverPoint = hoverPoint; + Invalidate(); + } + } } else { - if (CursorPosition.X >= 0) + if (HoverPoint.X >= 0) { - CursorPosition = new Point(-1, -1); + HoverPoint = CursorPoint = new Point(-1, -1); Invalidate(); } } @@ -179,28 +191,13 @@ namespace CodeMatrix protected override void OnMouseClick(MouseEventArgs e) { - if (CursorPosition.X >= 0 && Matrix[CursorPosition.X, CursorPosition.Y] != 0) + if (HoverPoint.X >= 0) { - if (_currDir == Directions.Horizontal) - { - if (CursorPosition.Y == SelectPoint.Y) - { - Matrix[CursorPosition.X, CursorPosition.Y] = 0; - _currDir = Directions.Vertical; - SelectPoint = CursorPosition; - Invalidate(); - } - } - else if (_currDir == Directions.Vertical) - { - if (CursorPosition.X == SelectPoint.X) - { - Matrix[CursorPosition.X, CursorPosition.Y] = 0; - _currDir = Directions.Horizontal; - SelectPoint = CursorPosition; - Invalidate(); - } - } + SelectPoint = HoverPoint; + HoverPoint = new Point(-1, -1); + Matrix[SelectPoint.X, SelectPoint.Y] = 0; + _currDir = _currDir == Directions.Horizontal ? Directions.Vertical : Directions.Horizontal; + Invalidate(); } base.OnMouseClick(e);