修改 主窗体UI

增加 自定义样式按钮
增加 窗体帮助类,显示窗体阴影与帮助窗体拖动
This commit is contained in:
jie65535 2021-01-22 23:10:01 +08:00
parent f50732f708
commit da4f15b3b0
6 changed files with 370 additions and 98 deletions

View 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);
}
}
}

View File

@ -46,6 +46,9 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="BaseControl\MyButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Common.cs" /> <Compile Include="Common.cs" />
<Compile Include="FormMain.cs"> <Compile Include="FormMain.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
@ -65,6 +68,7 @@
<Compile Include="UCCodeTarget.cs"> <Compile Include="UCCodeTarget.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Utils\FormHelper.cs" />
<EmbeddedResource Include="FormMain.resx"> <EmbeddedResource Include="FormMain.resx">
<DependentUpon>FormMain.cs</DependentUpon> <DependentUpon>FormMain.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

View File

@ -29,27 +29,188 @@ namespace CodeMatrix
/// </summary> /// </summary>
private void InitializeComponent() 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(); 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 // FormMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true; this.AutoSize = true;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(13)))), ((int)(((byte)(25)))));
this.ClientSize = new System.Drawing.Size(672, 323); 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.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.Margin = new System.Windows.Forms.Padding(0);
this.MaximizeBox = false; this.MaximizeBox = false;
this.Name = "FormMain"; this.Name = "FormMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Code Matrix"; this.Text = "Code Matrix";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FormMain_MouseDown);
this.FLPCodeTargets.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #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;
} }
} }

View File

@ -1,5 +1,6 @@
using System.Drawing; using System.Windows.Forms;
using System.Windows.Forms;
using CodeMatrix.Utils;
namespace CodeMatrix namespace CodeMatrix
{ {
@ -8,47 +9,103 @@ namespace CodeMatrix
public FormMain() public FormMain()
{ {
InitializeComponent(); InitializeComponent();
FormHelper.EnableFromDropShadow(Handle);
BackColor = Styles.Default.BackColor; BackColor = Styles.Default.BackColor;
var codeMatrix = new UCCodeMatrix(); foreach (UCCodeTarget codeTarget in FLPCodeTargets.Controls)
var codeQueue = new UCCodeQueue codeTarget.HoverCodeEvent += CodeTarget_HoverCodeEvent;
{
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) => //var codeMatrix = new UCCodeMatrix();
{ //var codeQueue = new UCCodeQueue
codeQueue.HoverCode = value; //{
foreach (var codeTarget in codeTargets) // Location = new Point(codeMatrix.Size.Width, 0)
codeTarget.HoverCode = value; //};
}; //var codeTargets = new UCCodeTarget[3];
codeMatrix.CodeSelectedEvent += (_, value) => //for (int i = 0, y = codeQueue.Size.Height; i < codeTargets.Length; y += codeTargets[i++].Size.Height)
{ //{
codeQueue.InputCode(value); // codeTargets[i] = new UCCodeTarget
foreach (var codeTarget in codeTargets) // {
codeTarget.InputCode(value); // Location = new Point(codeQueue.Location.X, y)
}; // };
// codeTargets[i].HoverCodeEvent += (_, value) =>
// {
// codeMatrix.HighlightCode = value;
// };
//}
Controls.Add(codeMatrix); //codeMatrix.HoverValueChangedEvent += (_, value) =>
Controls.Add(codeQueue); //{
Controls.AddRange(codeTargets); // 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; //Controls.Add(codeMatrix);
size.Width += codeQueue.Width; //Controls.Add(codeQueue);
ClientSize = size; //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
//}
} }
} }

View File

@ -18,16 +18,16 @@ namespace CodeMatrix
/// </summary> /// </summary>
private Size _CellSize; private Size _CellSize;
/// <summary>
/// The code matrix size
/// </summary>
private Size _CodeMatrixSize = new Size(5, 5);
/// <summary> /// <summary>
/// The code matrix rect /// The code matrix rect
/// </summary> /// </summary>
private RectangleF _CodeMatrixRect; private RectangleF _CodeMatrixRect;
/// <summary>
/// The columns
/// </summary>
private int _Columns = 5;
/// <summary> /// <summary>
/// The curr dir /// The curr dir
/// </summary> /// </summary>
@ -58,11 +58,6 @@ namespace CodeMatrix
/// </summary> /// </summary>
private byte[,] _Matrix; private byte[,] _Matrix;
/// <summary>
/// The rows
/// </summary>
private int _Rows = 5;
/// <summary> /// <summary>
/// The select point /// The select point
/// </summary> /// </summary>
@ -102,23 +97,20 @@ namespace CodeMatrix
Horizontal, Horizontal,
} }
/// <summary> public Size CodeMatrixSize
/// Gets or sets the columns.
/// </summary>
/// <value>
/// The columns.
/// </value>
/// <exception cref="ArgumentOutOfRangeException">Columns - 设置矩阵大小数值不能小于 {MinimumMatrixSize.Width} 或者大于 {MaximumMatrixSize.Width}</exception>
public int Columns
{ {
get => _Columns; get => _CodeMatrixSize;
set set
{ {
if (_Columns != value) if (_CodeMatrixSize != value)
{ {
if (value < MinimumMatrixSize.Width || value > MaximumMatrixSize.Width) if (value.Width < MinimumMatrixSize.Width
throw new ArgumentOutOfRangeException("Columns", value, $"设置矩阵大小数值不能小于 {MinimumMatrixSize.Width} 或者大于 {MaximumMatrixSize.Width}"); || value.Height < MinimumMatrixSize.Height
_Columns = value; || value.Width > MaximumMatrixSize.Width
|| value.Height > MaximumMatrixSize.Height)
throw new ArgumentOutOfRangeException("CodeMatrixSize", value,
$"设置矩阵大小数值不能小于 ({MinimumMatrixSize.Width}, {MinimumMatrixSize.Height}) 或者大于 ({MaximumMatrixSize.Width}, {MaximumMatrixSize.Height})");
_CodeMatrixSize = value;
OnCodeMatrixSizeChanged(); 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> /// <summary>
/// Gets or sets the hover point. /// Gets or sets the hover point.
/// </summary> /// </summary>
@ -281,28 +252,28 @@ namespace CodeMatrix
Cursor = Cursors.Default; 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); //var cellRect = new RectangleF(cellOffset, CellSize);
Brush brush; Brush brush;
string code; string code;
if (_Matrix[col, row] == 0) if (_Matrix[x, y] == 0)
{ {
code = "[ ]"; code = "[ ]";
brush = Styles.Default.EmptyCellBrush; brush = Styles.Default.EmptyCellBrush;
} }
else else
{ {
if (HoverPoint.X == col && HoverPoint.Y == row) if (HoverPoint.X == x && HoverPoint.Y == y)
brush = Styles.Default.SelectBrush; brush = Styles.Default.SelectBrush;
else else
brush = Styles.Default.CodeBrush; 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, e.Graphics.DrawRectangle(Styles.Default.SelectedCellBorderPen,
_CodeMatrixRect.X + cellOffset.X + 1, _CodeMatrixRect.X + cellOffset.X + 1,
@ -335,7 +306,7 @@ namespace CodeMatrix
/// </summary> /// </summary>
private void CalcCodeMatrixRect() 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); var blockOffset = new PointF((Width-blockSize.Width)/2, (Height-blockSize.Height)/2);
_CodeMatrixRect = new RectangleF(blockOffset, blockSize); _CodeMatrixRect = new RectangleF(blockOffset, blockSize);
} }
@ -345,10 +316,10 @@ namespace CodeMatrix
/// </summary> /// </summary>
private void GenerateCodeMatrix() private void GenerateCodeMatrix()
{ {
_Matrix = new byte[Columns, Rows]; _Matrix = new byte[CodeMatrixSize.Width, CodeMatrixSize.Height];
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++)
_Matrix[col, row] = Common.Codes[Common.Random.Next(Common.Codes.Length)]; _Matrix[x, y] = Common.Codes[Common.Random.Next(Common.Codes.Length)];
} }
/// <summary> /// <summary>
@ -357,7 +328,7 @@ namespace CodeMatrix
private void InitComponent() private void InitComponent()
{ {
_CellSize = Styles.Default.CellSizeA; _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); Size = MinimumSize + new Size(100, 10);
Margin = Padding.Empty; Margin = Padding.Empty;
DoubleBuffered = true; DoubleBuffered = true;
@ -372,7 +343,7 @@ namespace CodeMatrix
/// </summary> /// </summary>
private void OnCodeMatrixSizeChanged() 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) if (_IsLoaded)
ReloadCodeMatrix(); ReloadCodeMatrix();
} }

View 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));
}
}
}