From da4f15b3b04d2a05e19c113b763444bc1ac57d95 Mon Sep 17 00:00:00 2001
From: jie65535 <840465812@qq.com>
Date: Fri, 22 Jan 2021 23:10:01 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E4=B8=BB=E7=AA=97?=
=?UTF-8?q?=E4=BD=93UI=20=E5=A2=9E=E5=8A=A0=20=E8=87=AA=E5=AE=9A=E4=B9=89?=
=?UTF-8?q?=E6=A0=B7=E5=BC=8F=E6=8C=89=E9=92=AE=20=E5=A2=9E=E5=8A=A0=20?=
=?UTF-8?q?=E7=AA=97=E4=BD=93=E5=B8=AE=E5=8A=A9=E7=B1=BB=EF=BC=8C=E6=98=BE?=
=?UTF-8?q?=E7=A4=BA=E7=AA=97=E4=BD=93=E9=98=B4=E5=BD=B1=E4=B8=8E=E5=B8=AE?=
=?UTF-8?q?=E5=8A=A9=E7=AA=97=E4=BD=93=E6=8B=96=E5=8A=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CodeMatrix/BaseControl/MyButton.cs | 19 ++++
CodeMatrix/CodeMatrix.csproj | 4 +
CodeMatrix/FormMain.Designer.cs | 167 ++++++++++++++++++++++++++++-
CodeMatrix/FormMain.cs | 131 +++++++++++++++-------
CodeMatrix/UCCodeMatrix.cs | 87 +++++----------
CodeMatrix/Utils/FormHelper.cs | 60 +++++++++++
6 files changed, 370 insertions(+), 98 deletions(-)
create mode 100644 CodeMatrix/BaseControl/MyButton.cs
create mode 100644 CodeMatrix/Utils/FormHelper.cs
diff --git a/CodeMatrix/BaseControl/MyButton.cs b/CodeMatrix/BaseControl/MyButton.cs
new file mode 100644
index 0000000..f7a86f1
--- /dev/null
+++ b/CodeMatrix/BaseControl/MyButton.cs
@@ -0,0 +1,19 @@
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace CodeMatrix.BaseControl
+{
+ internal class MyButton : Button
+ {
+ public MyButton()
+ {
+ BackColor = Color.Transparent;
+ FlatAppearance.BorderColor = Styles.Default.SelectColor;
+ FlatAppearance.MouseDownBackColor = Color.FromArgb(100, Styles.Default.SelectColor);
+ FlatAppearance.MouseOverBackColor = Color.FromArgb(50, Styles.Default.SelectColor);
+ FlatStyle = FlatStyle.Flat;
+ ForeColor = Styles.Default.SelectColor;
+ Size = new Size(90, 30);
+ }
+ }
+}
\ No newline at end of file
diff --git a/CodeMatrix/CodeMatrix.csproj b/CodeMatrix/CodeMatrix.csproj
index 76d7ba6..4cf4e40 100644
--- a/CodeMatrix/CodeMatrix.csproj
+++ b/CodeMatrix/CodeMatrix.csproj
@@ -46,6 +46,9 @@
+
+ Component
+
Form
@@ -65,6 +68,7 @@
Component
+
FormMain.cs
diff --git a/CodeMatrix/FormMain.Designer.cs b/CodeMatrix/FormMain.Designer.cs
index 5b9fa07..1bc857e 100644
--- a/CodeMatrix/FormMain.Designer.cs
+++ b/CodeMatrix/FormMain.Designer.cs
@@ -29,27 +29,188 @@ namespace CodeMatrix
///
private void InitializeComponent()
{
+ this.FLPCodeTargets = new System.Windows.Forms.FlowLayoutPanel();
+ this.ucCodeTarget1 = new CodeMatrix.UCCodeTarget();
+ this.ucCodeTarget2 = new CodeMatrix.UCCodeTarget();
+ this.ucCodeTarget3 = new CodeMatrix.UCCodeTarget();
+ this.CodeQueue = new CodeMatrix.UCCodeQueue();
+ this.CodeMatrix = new CodeMatrix.UCCodeMatrix();
+ this.BtnMin = new CodeMatrix.BaseControl.MyButton();
+ this.BtnClose = new CodeMatrix.BaseControl.MyButton();
+ this.FLPCodeTargets.SuspendLayout();
this.SuspendLayout();
//
+ // FLPCodeTargets
+ //
+ this.FLPCodeTargets.Controls.Add(this.ucCodeTarget1);
+ this.FLPCodeTargets.Controls.Add(this.ucCodeTarget2);
+ this.FLPCodeTargets.Controls.Add(this.ucCodeTarget3);
+ this.FLPCodeTargets.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
+ this.FLPCodeTargets.Location = new System.Drawing.Point(321, 121);
+ this.FLPCodeTargets.Name = "FLPCodeTargets";
+ this.FLPCodeTargets.Padding = new System.Windows.Forms.Padding(1);
+ this.FLPCodeTargets.Size = new System.Drawing.Size(362, 210);
+ this.FLPCodeTargets.TabIndex = 4;
+ this.FLPCodeTargets.Paint += new System.Windows.Forms.PaintEventHandler(this.FLPCodeTargets_Paint);
+ //
+ // ucCodeTarget1
+ //
+ this.ucCodeTarget1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(13)))), ((int)(((byte)(25)))));
+ this.ucCodeTarget1.BufferSize = 4;
+ this.ucCodeTarget1.Font = new System.Drawing.Font("微软雅黑", 12F);
+ this.ucCodeTarget1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(208)))), ((int)(((byte)(236)))), ((int)(((byte)(92)))));
+ this.ucCodeTarget1.HoverCode = ((byte)(0));
+ this.ucCodeTarget1.Location = new System.Drawing.Point(1, 1);
+ this.ucCodeTarget1.Margin = new System.Windows.Forms.Padding(0);
+ this.ucCodeTarget1.MinimumSize = new System.Drawing.Size(144, 41);
+ this.ucCodeTarget1.Name = "ucCodeTarget1";
+ this.ucCodeTarget1.Padding = new System.Windows.Forms.Padding(10, 5, 10, 5);
+ this.ucCodeTarget1.Size = new System.Drawing.Size(144, 41);
+ this.ucCodeTarget1.TabIndex = 0;
+ this.ucCodeTarget1.TargetLength = 3;
+ this.ucCodeTarget1.Text = "ucCodeTarget1";
+ //
+ // ucCodeTarget2
+ //
+ this.ucCodeTarget2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(13)))), ((int)(((byte)(25)))));
+ this.ucCodeTarget2.BufferSize = 4;
+ this.ucCodeTarget2.Font = new System.Drawing.Font("微软雅黑", 12F);
+ this.ucCodeTarget2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(208)))), ((int)(((byte)(236)))), ((int)(((byte)(92)))));
+ this.ucCodeTarget2.HoverCode = ((byte)(0));
+ this.ucCodeTarget2.Location = new System.Drawing.Point(1, 42);
+ this.ucCodeTarget2.Margin = new System.Windows.Forms.Padding(0);
+ this.ucCodeTarget2.MinimumSize = new System.Drawing.Size(144, 41);
+ this.ucCodeTarget2.Name = "ucCodeTarget2";
+ this.ucCodeTarget2.Padding = new System.Windows.Forms.Padding(10, 5, 10, 5);
+ this.ucCodeTarget2.Size = new System.Drawing.Size(144, 41);
+ this.ucCodeTarget2.TabIndex = 1;
+ this.ucCodeTarget2.TargetLength = 3;
+ this.ucCodeTarget2.Text = "ucCodeTarget2";
+ //
+ // ucCodeTarget3
+ //
+ this.ucCodeTarget3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(13)))), ((int)(((byte)(25)))));
+ this.ucCodeTarget3.BufferSize = 4;
+ this.ucCodeTarget3.Font = new System.Drawing.Font("微软雅黑", 12F);
+ this.ucCodeTarget3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(208)))), ((int)(((byte)(236)))), ((int)(((byte)(92)))));
+ this.ucCodeTarget3.HoverCode = ((byte)(0));
+ this.ucCodeTarget3.Location = new System.Drawing.Point(1, 83);
+ this.ucCodeTarget3.Margin = new System.Windows.Forms.Padding(0);
+ this.ucCodeTarget3.MinimumSize = new System.Drawing.Size(144, 41);
+ this.ucCodeTarget3.Name = "ucCodeTarget3";
+ this.ucCodeTarget3.Padding = new System.Windows.Forms.Padding(10, 5, 10, 5);
+ this.ucCodeTarget3.Size = new System.Drawing.Size(144, 41);
+ this.ucCodeTarget3.TabIndex = 2;
+ this.ucCodeTarget3.TargetLength = 3;
+ this.ucCodeTarget3.Text = "ucCodeTarget3";
+ //
+ // CodeQueue
+ //
+ this.CodeQueue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(13)))), ((int)(((byte)(25)))));
+ this.CodeQueue.BufferSize = 4;
+ this.CodeQueue.Font = new System.Drawing.Font("微软雅黑", 12F);
+ this.CodeQueue.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(208)))), ((int)(((byte)(236)))), ((int)(((byte)(92)))));
+ this.CodeQueue.HoverCode = ((byte)(0));
+ this.CodeQueue.Location = new System.Drawing.Point(323, 67);
+ this.CodeQueue.Margin = new System.Windows.Forms.Padding(0);
+ this.CodeQueue.MinimumSize = new System.Drawing.Size(144, 51);
+ this.CodeQueue.Name = "CodeQueue";
+ this.CodeQueue.Padding = new System.Windows.Forms.Padding(10);
+ this.CodeQueue.Size = new System.Drawing.Size(144, 51);
+ this.CodeQueue.TabIndex = 3;
+ this.CodeQueue.Text = "ucCodeQueue1";
+ //
+ // CodeMatrix
+ //
+ this.CodeMatrix.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(13)))), ((int)(((byte)(25)))));
+ this.CodeMatrix.CodeMatrixSize = new System.Drawing.Size(5, 5);
+ this.CodeMatrix.Cursor = System.Windows.Forms.Cursors.Default;
+ this.CodeMatrix.Font = new System.Drawing.Font("微软雅黑", 14F);
+ this.CodeMatrix.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(208)))), ((int)(((byte)(236)))), ((int)(((byte)(92)))));
+ this.CodeMatrix.HighlightCode = ((byte)(0));
+ this.CodeMatrix.Location = new System.Drawing.Point(18, 121);
+ this.CodeMatrix.Margin = new System.Windows.Forms.Padding(0);
+ this.CodeMatrix.MinimumSize = new System.Drawing.Size(200, 200);
+ this.CodeMatrix.Name = "CodeMatrix";
+ this.CodeMatrix.Size = new System.Drawing.Size(300, 210);
+ this.CodeMatrix.TabIndex = 2;
+ this.CodeMatrix.Text = "ucCodeMatrix1";
+ this.CodeMatrix.CodeSelectedEvent += new System.EventHandler(this.CodeMatrix_CodeSelectedEvent);
+ this.CodeMatrix.HoverValueChangedEvent += new System.EventHandler(this.CodeMatrix_HoverValueChangedEvent);
+ //
+ // BtnMin
+ //
+ this.BtnMin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.BtnMin.BackColor = System.Drawing.Color.Transparent;
+ this.BtnMin.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(232)))), ((int)(((byte)(228)))));
+ this.BtnMin.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(109)))), ((int)(((byte)(232)))), ((int)(((byte)(228)))));
+ this.BtnMin.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(109)))), ((int)(((byte)(232)))), ((int)(((byte)(228)))));
+ this.BtnMin.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+ this.BtnMin.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold);
+ this.BtnMin.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(232)))), ((int)(((byte)(228)))));
+ this.BtnMin.Location = new System.Drawing.Point(637, 12);
+ this.BtnMin.Name = "BtnMin";
+ this.BtnMin.Size = new System.Drawing.Size(30, 30);
+ this.BtnMin.TabIndex = 1;
+ this.BtnMin.TabStop = false;
+ this.BtnMin.Text = "-";
+ this.BtnMin.UseVisualStyleBackColor = false;
+ this.BtnMin.Click += new System.EventHandler(this.BtnMin_Click);
+ //
+ // BtnClose
+ //
+ this.BtnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.BtnClose.BackColor = System.Drawing.Color.Transparent;
+ this.BtnClose.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(232)))), ((int)(((byte)(228)))));
+ this.BtnClose.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
+ this.BtnClose.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(109)))), ((int)(((byte)(232)))), ((int)(((byte)(228)))));
+ this.BtnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+ this.BtnClose.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold);
+ this.BtnClose.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(232)))), ((int)(((byte)(228)))));
+ this.BtnClose.Location = new System.Drawing.Point(673, 12);
+ this.BtnClose.Name = "BtnClose";
+ this.BtnClose.Size = new System.Drawing.Size(30, 30);
+ this.BtnClose.TabIndex = 1;
+ this.BtnClose.TabStop = false;
+ this.BtnClose.Text = "×";
+ this.BtnClose.UseVisualStyleBackColor = false;
+ this.BtnClose.Click += new System.EventHandler(this.BtnClose_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
- this.BackColor = System.Drawing.Color.White;
- this.ClientSize = new System.Drawing.Size(672, 323);
+ this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(13)))), ((int)(((byte)(25)))));
+ this.ClientSize = new System.Drawing.Size(715, 380);
+ this.Controls.Add(this.FLPCodeTargets);
+ this.Controls.Add(this.CodeQueue);
+ this.Controls.Add(this.CodeMatrix);
+ this.Controls.Add(this.BtnMin);
+ this.Controls.Add(this.BtnClose);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Margin = new System.Windows.Forms.Padding(0);
this.MaximizeBox = false;
this.Name = "FormMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Code Matrix";
+ this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FormMain_MouseDown);
+ this.FLPCodeTargets.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
+
+ private BaseControl.MyButton BtnClose;
+ private BaseControl.MyButton BtnMin;
+ private UCCodeMatrix CodeMatrix;
+ private UCCodeQueue CodeQueue;
+ private System.Windows.Forms.FlowLayoutPanel FLPCodeTargets;
+ private UCCodeTarget ucCodeTarget1;
+ private UCCodeTarget ucCodeTarget2;
+ private UCCodeTarget ucCodeTarget3;
}
}
diff --git a/CodeMatrix/FormMain.cs b/CodeMatrix/FormMain.cs
index 4308c6b..bfdabb5 100644
--- a/CodeMatrix/FormMain.cs
+++ b/CodeMatrix/FormMain.cs
@@ -1,5 +1,6 @@
-using System.Drawing;
-using System.Windows.Forms;
+using System.Windows.Forms;
+
+using CodeMatrix.Utils;
namespace CodeMatrix
{
@@ -8,47 +9,103 @@ namespace CodeMatrix
public FormMain()
{
InitializeComponent();
+ FormHelper.EnableFromDropShadow(Handle);
BackColor = Styles.Default.BackColor;
- var codeMatrix = new UCCodeMatrix();
- var codeQueue = new UCCodeQueue
- {
- Location = new Point(codeMatrix.Size.Width, 0)
- };
- var codeTargets = new UCCodeTarget[3];
- for (int i = 0, y = codeQueue.Size.Height; i < codeTargets.Length; y += codeTargets[i++].Size.Height)
- {
- codeTargets[i] = new UCCodeTarget
- {
- Location = new Point(codeQueue.Location.X, y)
- };
- codeTargets[i].HoverCodeEvent += (_, value) =>
- {
- codeMatrix.HighlightCode = value;
- };
- }
+ foreach (UCCodeTarget codeTarget in FLPCodeTargets.Controls)
+ codeTarget.HoverCodeEvent += CodeTarget_HoverCodeEvent;
- codeMatrix.HoverValueChangedEvent += (_, value) =>
- {
- codeQueue.HoverCode = value;
- foreach (var codeTarget in codeTargets)
- codeTarget.HoverCode = value;
- };
- codeMatrix.CodeSelectedEvent += (_, value) =>
- {
- codeQueue.InputCode(value);
- foreach (var codeTarget in codeTargets)
- codeTarget.InputCode(value);
- };
+ //var codeMatrix = new UCCodeMatrix();
+ //var codeQueue = new UCCodeQueue
+ //{
+ // Location = new Point(codeMatrix.Size.Width, 0)
+ //};
+ //var codeTargets = new UCCodeTarget[3];
+ //for (int i = 0, y = codeQueue.Size.Height; i < codeTargets.Length; y += codeTargets[i++].Size.Height)
+ //{
+ // codeTargets[i] = new UCCodeTarget
+ // {
+ // Location = new Point(codeQueue.Location.X, y)
+ // };
+ // codeTargets[i].HoverCodeEvent += (_, value) =>
+ // {
+ // codeMatrix.HighlightCode = value;
+ // };
+ //}
- Controls.Add(codeMatrix);
- Controls.Add(codeQueue);
- Controls.AddRange(codeTargets);
+ //codeMatrix.HoverValueChangedEvent += (_, value) =>
+ //{
+ // codeQueue.HoverCode = value;
+ // foreach (var codeTarget in codeTargets)
+ // codeTarget.HoverCode = value;
+ //};
+ //codeMatrix.CodeSelectedEvent += (_, value) =>
+ //{
+ // codeQueue.InputCode(value);
+ // foreach (var codeTarget in codeTargets)
+ // codeTarget.InputCode(value);
+ //};
- var size = codeMatrix.Size;
- size.Width += codeQueue.Width;
- ClientSize = size;
+ //Controls.Add(codeMatrix);
+ //Controls.Add(codeQueue);
+ //Controls.AddRange(codeTargets);
+
+ //var size = codeMatrix.Size;
+ //size.Width += codeQueue.Width;
+ //ClientSize = size;
}
+
+ protected override void OnPaint(PaintEventArgs e)
+ {
+ base.OnPaint(e);
+ e.Graphics.DrawRectangle(Styles.Default.DefaultBorderPen, 0, 0, Width - 1, Height - 1);
+ }
+
+ private void BtnMin_Click(object sender, System.EventArgs e)
+ {
+ WindowState = FormWindowState.Minimized;
+ }
+
+ private void BtnClose_Click(object sender, System.EventArgs e)
+ {
+ Close();
+ }
+
+ private void FormMain_MouseDown(object sender, MouseEventArgs e)
+ {
+ FormHelper.OnMouseDown(Handle);
+ }
+
+ private void FLPCodeTargets_Paint(object sender, PaintEventArgs e)
+ {
+ e.Graphics.DrawRectangle(Styles.Default.DefaultBorderPen, 0, 0, FLPCodeTargets.Width - 1, FLPCodeTargets.Height - 1);
+ }
+
+ private void CodeMatrix_CodeSelectedEvent(object sender, byte e)
+ {
+ CodeQueue.InputCode(e);
+ foreach (UCCodeTarget codeTarget in FLPCodeTargets.Controls)
+ codeTarget.InputCode(e);
+ }
+
+ private void CodeMatrix_HoverValueChangedEvent(object sender, byte e)
+ {
+ CodeQueue.HoverCode = e;
+ foreach (UCCodeTarget codeTarget in FLPCodeTargets.Controls)
+ codeTarget.HoverCode = e;
+ }
+
+ private void CodeTarget_HoverCodeEvent(object sender, byte e)
+ {
+ CodeMatrix.HighlightCode = e;
+ foreach (UCCodeTarget codeTarget in FLPCodeTargets.Controls)
+ codeTarget.HoverCode = e;
+ }
+
+ //private void CodeTarget_CodeTargetStateChangedEvent(object sender, System.EventArgs e)
+ //{
+ // // TODO
+ //}
}
}
\ No newline at end of file
diff --git a/CodeMatrix/UCCodeMatrix.cs b/CodeMatrix/UCCodeMatrix.cs
index d66646e..005ceab 100644
--- a/CodeMatrix/UCCodeMatrix.cs
+++ b/CodeMatrix/UCCodeMatrix.cs
@@ -18,16 +18,16 @@ namespace CodeMatrix
///
private Size _CellSize;
+ ///
+ /// The code matrix size
+ ///
+ private Size _CodeMatrixSize = new Size(5, 5);
+
///
/// The code matrix rect
///
private RectangleF _CodeMatrixRect;
- ///
- /// The columns
- ///
- private int _Columns = 5;
-
///
/// The curr dir
///
@@ -58,11 +58,6 @@ namespace CodeMatrix
///
private byte[,] _Matrix;
- ///
- /// The rows
- ///
- private int _Rows = 5;
-
///
/// The select point
///
@@ -102,23 +97,20 @@ namespace CodeMatrix
Horizontal,
}
- ///
- /// Gets or sets the columns.
- ///
- ///
- /// The columns.
- ///
- /// Columns - 设置矩阵大小数值不能小于 {MinimumMatrixSize.Width} 或者大于 {MaximumMatrixSize.Width}
- public int Columns
+ public Size CodeMatrixSize
{
- get => _Columns;
+ get => _CodeMatrixSize;
set
{
- if (_Columns != value)
+ if (_CodeMatrixSize != value)
{
- if (value < MinimumMatrixSize.Width || value > MaximumMatrixSize.Width)
- throw new ArgumentOutOfRangeException("Columns", value, $"设置矩阵大小数值不能小于 {MinimumMatrixSize.Width} 或者大于 {MaximumMatrixSize.Width}");
- _Columns = value;
+ if (value.Width < MinimumMatrixSize.Width
+ || value.Height < MinimumMatrixSize.Height
+ || value.Width > MaximumMatrixSize.Width
+ || value.Height > MaximumMatrixSize.Height)
+ throw new ArgumentOutOfRangeException("CodeMatrixSize", value,
+ $"设置矩阵大小数值不能小于 ({MinimumMatrixSize.Width}, {MinimumMatrixSize.Height}) 或者大于 ({MaximumMatrixSize.Width}, {MaximumMatrixSize.Height})");
+ _CodeMatrixSize = value;
OnCodeMatrixSizeChanged();
}
}
@@ -143,27 +135,6 @@ namespace CodeMatrix
}
}
- ///
- /// Gets or sets the rows.
- ///
- ///
- /// The rows.
- ///
- public int Rows
- {
- get => _Rows;
- set
- {
- if (_Rows != value)
- {
- if (value < MinimumMatrixSize.Height || value > MaximumMatrixSize.Height)
- throw new ArgumentOutOfRangeException("value", value, $"设置矩阵大小数值不能小于 {MinimumMatrixSize.Height} 或者大于 {MaximumMatrixSize.Height}");
- _Rows = value;
- OnCodeMatrixSizeChanged();
- }
- }
- }
-
///
/// Gets or sets the hover point.
///
@@ -281,28 +252,28 @@ namespace CodeMatrix
Cursor = Cursors.Default;
}
- for (int col = 0; col < Columns; col++)
+ for (int x = 0; x < CodeMatrixSize.Width; x++)
{
- for (int row = 0; row < Rows; row++)
+ for (int y = 0; y < CodeMatrixSize.Height; y++)
{
- var cellOffset = new PointF(col*_CellSize.Width, row*_CellSize.Height);
+ var cellOffset = new PointF(x*_CellSize.Width, y*_CellSize.Height);
//var cellRect = new RectangleF(cellOffset, CellSize);
Brush brush;
string code;
- if (_Matrix[col, row] == 0)
+ if (_Matrix[x, y] == 0)
{
code = "[ ]";
brush = Styles.Default.EmptyCellBrush;
}
else
{
- if (HoverPoint.X == col && HoverPoint.Y == row)
+ if (HoverPoint.X == x && HoverPoint.Y == y)
brush = Styles.Default.SelectBrush;
else
brush = Styles.Default.CodeBrush;
- code = _Matrix[col, row].ToString("X2");
+ code = _Matrix[x, y].ToString("X2");
}
- if (HighlightCode != 0 && HighlightCode == _Matrix[col, row])
+ if (HighlightCode != 0 && HighlightCode == _Matrix[x, y])
{
e.Graphics.DrawRectangle(Styles.Default.SelectedCellBorderPen,
_CodeMatrixRect.X + cellOffset.X + 1,
@@ -335,7 +306,7 @@ namespace CodeMatrix
///
private void CalcCodeMatrixRect()
{
- var blockSize = new SizeF(Columns*_CellSize.Width, Rows*_CellSize.Height);
+ var blockSize = new SizeF(CodeMatrixSize.Width*_CellSize.Width, CodeMatrixSize.Height*_CellSize.Height);
var blockOffset = new PointF((Width-blockSize.Width)/2, (Height-blockSize.Height)/2);
_CodeMatrixRect = new RectangleF(blockOffset, blockSize);
}
@@ -345,10 +316,10 @@ namespace CodeMatrix
///
private void GenerateCodeMatrix()
{
- _Matrix = new byte[Columns, Rows];
- for (int col = 0; col < Columns; col++)
- for (int row = 0; row < Rows; row++)
- _Matrix[col, row] = Common.Codes[Common.Random.Next(Common.Codes.Length)];
+ _Matrix = new byte[CodeMatrixSize.Width, CodeMatrixSize.Height];
+ for (int x = 0; x < CodeMatrixSize.Width; x++)
+ for (int y = 0; y < CodeMatrixSize.Height; y++)
+ _Matrix[x, y] = Common.Codes[Common.Random.Next(Common.Codes.Length)];
}
///
@@ -357,7 +328,7 @@ namespace CodeMatrix
private void InitComponent()
{
_CellSize = Styles.Default.CellSizeA;
- MinimumSize = new Size(_CellSize.Width * Columns, _CellSize.Height * Rows);
+ MinimumSize = new Size(_CellSize.Width * CodeMatrixSize.Width, _CellSize.Height * CodeMatrixSize.Height);
Size = MinimumSize + new Size(100, 10);
Margin = Padding.Empty;
DoubleBuffered = true;
@@ -372,7 +343,7 @@ namespace CodeMatrix
///
private void OnCodeMatrixSizeChanged()
{
- MinimumSize = new Size(_CellSize.Width * Columns, _CellSize.Height * Rows);
+ MinimumSize = new Size(_CellSize.Width * CodeMatrixSize.Width, _CellSize.Height * CodeMatrixSize.Height);
if (_IsLoaded)
ReloadCodeMatrix();
}
diff --git a/CodeMatrix/Utils/FormHelper.cs b/CodeMatrix/Utils/FormHelper.cs
new file mode 100644
index 0000000..082ad97
--- /dev/null
+++ b/CodeMatrix/Utils/FormHelper.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace CodeMatrix.Utils
+{
+ public static class FormHelper
+ {
+ [DllImport("user32.dll")]
+ static extern bool ReleaseCapture();
+
+ [DllImport("user32.dll")]
+ static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
+
+ const int WM_SYSCOMMAND = 0x0112;
+ const int SC_MOVE = 0xF010;
+ const int HTCAPTION = 0x0002;
+
+ public static void OnMouseDown(IntPtr handle)
+ {
+ ReleaseCapture();
+ SendMessage(handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
+ }
+
+ const int CS_DropSHADOW = 0x20000;
+ const int GCL_STYLE = -26;
+
+ static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
+ {
+ if (IntPtr.Size > 4)
+ return SetClassLongPtr64(hWnd, nIndex, dwNewLong);
+ else
+ return new IntPtr(SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32())));
+ }
+
+ [DllImport("user32.dll", EntryPoint = "SetClassLong")]
+ static extern uint SetClassLongPtr32(IntPtr hWnd, int nIndex, uint dwNewLong);
+
+ [DllImport("user32.dll", EntryPoint = "SetClassLongPtr")]
+ static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
+ static IntPtr GetClassLongPtr(IntPtr hWnd, int nIndex)
+ {
+ if (IntPtr.Size > 4)
+ return GetClassLongPtr64(hWnd, nIndex);
+ else
+ return new IntPtr(GetClassLongPtr32(hWnd, nIndex));
+ }
+
+ [DllImport("user32.dll", EntryPoint = "GetClassLong")]
+ static extern uint GetClassLongPtr32(IntPtr hWnd, int nIndex);
+
+ [DllImport("user32.dll", EntryPoint = "GetClassLongPtr")]
+ static extern IntPtr GetClassLongPtr64(IntPtr hWnd, int nIndex);
+
+
+ public static void EnableFromDropShadow(IntPtr handle)
+ {
+ SetClassLong(handle, GCL_STYLE, (IntPtr)((long)GetClassLongPtr(handle, GCL_STYLE) | CS_DropSHADOW));
+ }
+ }
+}
\ No newline at end of file