diff --git a/CodeMatrix/FormMain.Designer.cs b/CodeMatrix/FormMain.Designer.cs index d56dffb..5b9fa07 100644 --- a/CodeMatrix/FormMain.Designer.cs +++ b/CodeMatrix/FormMain.Designer.cs @@ -39,7 +39,9 @@ namespace CodeMatrix this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(672, 323); 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.Margin = new System.Windows.Forms.Padding(0); + this.MaximizeBox = false; this.Name = "FormMain"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Code Matrix"; diff --git a/CodeMatrix/FormMain.cs b/CodeMatrix/FormMain.cs index f7d9f3a..bdb8292 100644 --- a/CodeMatrix/FormMain.cs +++ b/CodeMatrix/FormMain.cs @@ -15,10 +15,18 @@ namespace CodeMatrix public FormMain() { InitializeComponent(); - - var matrix = new UCCodeMatrix(); - Controls.Add(matrix); - ClientSize = matrix.Size; + + BackColor = Styles.Default.BackColor; + + var codeMatrix = new UCCodeMatrix(); + var codeQueue = new UCCodeQueue(); + codeQueue.Location = new Point(codeMatrix.Size.Width, 0); + Controls.Add(codeMatrix); + Controls.Add(codeQueue); + + var size = codeMatrix.Size; + size.Width += codeQueue.Width; + ClientSize = size; } } diff --git a/CodeMatrix/Styles.cs b/CodeMatrix/Styles.cs index d3add40..d00deee 100644 --- a/CodeMatrix/Styles.cs +++ b/CodeMatrix/Styles.cs @@ -8,23 +8,43 @@ namespace CodeMatrix public Styles() { - Font = new Font("微软雅黑", 14); + CodeFontA = new Font("微软雅黑", 14); + CodeFontB = new Font("微软雅黑", 12); BackColor = Color.FromArgb(18, 13, 25); - ForeColor = Color.FromArgb(208, 236, 92); - CodeBrush = new SolidBrush(Color.FromArgb(208, 236, 92)); + CodeColor = Color.FromArgb(208, 236, 92); + SelectColor = Color.FromArgb(109, 232, 228); + CodeBrush = new SolidBrush(CodeColor); + SelectBrush = new SolidBrush(SelectColor); EmptyCellBrush = new SolidBrush(Color.FromArgb(65, 52, 76)); DefaultLineBackColor = new SolidBrush(Color.FromArgb(42, 43, 60)); SelectLineBackColor = new SolidBrush(Color.FromArgb(32, 31, 28)); - SelectCellBorderPen = new Pen(Color.FromArgb(109, 232, 228), 1); + SelectCellBorderPen = new Pen(SelectColor, 1); + EmptyCellBorderPen = new Pen(Color.FromArgb(116, 144, 0), 1) + { + DashStyle = System.Drawing.Drawing2D.DashStyle.Custom, + DashPattern = new float[2] { 4, 4 } + }; + SelectedCellBorderPen = new Pen(CodeColor, 1) + { + DashStyle = System.Drawing.Drawing2D.DashStyle.Custom, + DashPattern = new float[2] { 3, 3 } + }; + DefaultBorderPen = new Pen(CodeColor, 1); } - public Font Font { get; set; } + public Font CodeFontA { get; set; } + public Font CodeFontB { get; set; } public Color BackColor { get; set; } - public Color ForeColor { get; set; } + public Color CodeColor { get; set; } + public Color SelectColor { get; set; } public Brush CodeBrush { get; set; } + public Brush SelectBrush { get; set; } public Brush EmptyCellBrush { get; set; } public Brush DefaultLineBackColor { get; set; } public Brush SelectLineBackColor { get; set; } public Pen SelectCellBorderPen { get; set; } + public Pen EmptyCellBorderPen { get; set; } + public Pen SelectedCellBorderPen { get; set; } + public Pen DefaultBorderPen { get; set; } } } \ No newline at end of file diff --git a/CodeMatrix/UCCodeMatrix.cs b/CodeMatrix/UCCodeMatrix.cs index b582c6f..586143c 100644 --- a/CodeMatrix/UCCodeMatrix.cs +++ b/CodeMatrix/UCCodeMatrix.cs @@ -44,8 +44,8 @@ namespace CodeMatrix private void InitData() { - Rows = 9; - Columns = 16; + Rows = 7; + Columns = 7; CellSize = new SizeF(40, 40); _currDir = Directions.Horizontal; HoverPoint = new Point(-1, -1); @@ -57,9 +57,9 @@ namespace CodeMatrix Margin = Padding.Empty; DoubleBuffered = true; - Font = Styles.Default.Font; + Font = Styles.Default.CodeFontA; BackColor = Styles.Default.BackColor; - ForeColor = Styles.Default.ForeColor; + ForeColor = Styles.Default.CodeColor; } private bool _IsLoaded; @@ -137,7 +137,10 @@ namespace CodeMatrix } else { - brush = Styles.Default.CodeBrush; + if (HoverPoint.X == col && HoverPoint.Y == row) + brush = Styles.Default.SelectBrush; + else + brush = Styles.Default.CodeBrush; code = Matrix[col, row].ToString("X2"); } var codeSize = e.Graphics.MeasureString(code, Font); @@ -147,6 +150,7 @@ namespace CodeMatrix } } + e.Graphics.DrawRectangle(Styles.Default.DefaultBorderPen, 0, 0, Width - 1, Height - 1); //e.Graphics.DrawString(_paintCount.ToString(), Font, Styles.Default.CodeBrush, 0, 0); } diff --git a/CodeMatrix/UCCodeQueue.cs b/CodeMatrix/UCCodeQueue.cs index b20f5a6..43c6cb0 100644 --- a/CodeMatrix/UCCodeQueue.cs +++ b/CodeMatrix/UCCodeQueue.cs @@ -10,8 +10,9 @@ namespace CodeMatrix { class UCCodeQueue : Control { - public SizeF CellSize { get; private set; } + public Size CellSize { get; private set; } public Padding CellMargin { get; set; } + public byte HoverCode { get; set; } public int BufferSize { get; set; } public int CurrIndex { get; private set; } public byte[] Buffer { get; } = new byte[32]; @@ -24,25 +25,71 @@ namespace CodeMatrix private void InitData() { - CellSize = new SizeF(40, 40); + CellSize = new Size(25, 25); BufferSize = 7; - CurrIndex = 0; + + CurrIndex = 4; + HoverCode = 0x55; + Buffer[0] = 0xE9; + Buffer[1] = 0x55; + Buffer[2] = 0x1C; + Buffer[3] = 0xBD; } private void InitComponent() { Margin = Padding.Empty; + Padding = new Padding(10); CellMargin = new Padding(3); - MinimumSize = new Size((int)((CellSize.Width + CellMargin.Horizontal) * BufferSize), (int)(CellSize.Height + CellMargin.Vertical)); + MinimumSize = new Size((CellSize.Width + CellMargin.Horizontal) * BufferSize + Padding.Horizontal, + CellSize.Height + CellMargin.Vertical + Padding.Vertical); DoubleBuffered = true; - Font = Styles.Default.Font; + Font = Styles.Default.CodeFontB; BackColor = Styles.Default.BackColor; - ForeColor = Styles.Default.ForeColor; + ForeColor = Styles.Default.CodeColor; } protected override void OnPaint(PaintEventArgs e) { + var cellOffset = new Rectangle(Padding.Left + CellMargin.Left, + Padding.Top + CellMargin.Top, + CellSize.Width-1, + CellSize.Height-1); + var cellOffsetWidth = CellSize.Width + CellMargin.Horizontal; + int index = 0; + for (; index < CurrIndex; index++) + { + e.Graphics.DrawRectangle(Styles.Default.SelectedCellBorderPen, cellOffset); + var code = Buffer[index].ToString("X2"); + var codeSize = e.Graphics.MeasureString(code, Font); + var codeOffset = new PointF((CellSize.Width-codeSize.Width)/2, (CellSize.Height-codeSize.Height)/2); + var codePoint = new PointF(codeOffset.X+cellOffset.X, codeOffset.Y+cellOffset.Y); + e.Graphics.DrawString(code, Font, Styles.Default.CodeBrush, codePoint); + cellOffset.X += cellOffsetWidth; + } + if (HoverCode > 0) + { + e.Graphics.DrawRectangle(Styles.Default.SelectCellBorderPen, cellOffset); + var code = HoverCode.ToString("X2"); + var codeSize = e.Graphics.MeasureString(code, Font); + var codeOffset = new PointF((CellSize.Width-codeSize.Width)/2, (CellSize.Height-codeSize.Height)/2); + var codePoint = new PointF(codeOffset.X+cellOffset.X, codeOffset.Y+cellOffset.Y); + e.Graphics.DrawString(code, Font, Styles.Default.SelectBrush, codePoint); + + + cellOffset.X += cellOffsetWidth; + index++; + } + for (; index < BufferSize; index++) + { + e.Graphics.DrawRectangle(Styles.Default.EmptyCellBorderPen, cellOffset); + cellOffset.X += cellOffsetWidth; + } + + + e.Graphics.DrawRectangle(Styles.Default.DefaultBorderPen, 0, 0, Width - 1, Height - 1); + base.OnPaint(e); } }