mirror of
https://github.com/jie65535/CodeMatrix.git
synced 2025-07-31 18:19:13 +08:00
修改 主窗体UI
增加 自定义样式按钮 增加 窗体帮助类,显示窗体阴影与帮助窗体拖动
This commit is contained in:
parent
f50732f708
commit
da4f15b3b0
19
CodeMatrix/BaseControl/MyButton.cs
Normal file
19
CodeMatrix/BaseControl/MyButton.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -46,6 +46,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseControl\MyButton.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Common.cs" />
|
||||
<Compile Include="FormMain.cs">
|
||||
<SubType>Form</SubType>
|
||||
@ -65,6 +68,7 @@
|
||||
<Compile Include="UCCodeTarget.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Utils\FormHelper.cs" />
|
||||
<EmbeddedResource Include="FormMain.resx">
|
||||
<DependentUpon>FormMain.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
167
CodeMatrix/FormMain.Designer.cs
generated
167
CodeMatrix/FormMain.Designer.cs
generated
@ -29,27 +29,188 @@ namespace CodeMatrix
|
||||
/// </summary>
|
||||
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<byte>(this.CodeMatrix_CodeSelectedEvent);
|
||||
this.CodeMatrix.HoverValueChangedEvent += new System.EventHandler<byte>(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
//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;
|
||||
// };
|
||||
//}
|
||||
|
||||
//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);
|
||||
//};
|
||||
|
||||
//Controls.Add(codeMatrix);
|
||||
//Controls.Add(codeQueue);
|
||||
//Controls.AddRange(codeTargets);
|
||||
|
||||
//var size = codeMatrix.Size;
|
||||
//size.Width += codeQueue.Width;
|
||||
//ClientSize = size;
|
||||
}
|
||||
|
||||
codeMatrix.HoverValueChangedEvent += (_, value) =>
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
Controls.Add(codeMatrix);
|
||||
Controls.Add(codeQueue);
|
||||
Controls.AddRange(codeTargets);
|
||||
|
||||
var size = codeMatrix.Size;
|
||||
size.Width += codeQueue.Width;
|
||||
ClientSize = size;
|
||||
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
|
||||
//}
|
||||
}
|
||||
}
|
@ -18,16 +18,16 @@ namespace CodeMatrix
|
||||
/// </summary>
|
||||
private Size _CellSize;
|
||||
|
||||
/// <summary>
|
||||
/// The code matrix size
|
||||
/// </summary>
|
||||
private Size _CodeMatrixSize = new Size(5, 5);
|
||||
|
||||
/// <summary>
|
||||
/// The code matrix rect
|
||||
/// </summary>
|
||||
private RectangleF _CodeMatrixRect;
|
||||
|
||||
/// <summary>
|
||||
/// The columns
|
||||
/// </summary>
|
||||
private int _Columns = 5;
|
||||
|
||||
/// <summary>
|
||||
/// The curr dir
|
||||
/// </summary>
|
||||
@ -58,11 +58,6 @@ namespace CodeMatrix
|
||||
/// </summary>
|
||||
private byte[,] _Matrix;
|
||||
|
||||
/// <summary>
|
||||
/// The rows
|
||||
/// </summary>
|
||||
private int _Rows = 5;
|
||||
|
||||
/// <summary>
|
||||
/// The select point
|
||||
/// </summary>
|
||||
@ -102,23 +97,20 @@ namespace CodeMatrix
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the columns.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The columns.
|
||||
/// </value>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Columns - 设置矩阵大小数值不能小于 {MinimumMatrixSize.Width} 或者大于 {MaximumMatrixSize.Width}</exception>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the rows.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The rows.
|
||||
/// </value>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the hover point.
|
||||
/// </summary>
|
||||
@ -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
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
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)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
60
CodeMatrix/Utils/FormHelper.cs
Normal file
60
CodeMatrix/Utils/FormHelper.cs
Normal file
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user