mirror of
https://github.com/jie65535/CodeMatrix.git
synced 2025-06-01 17:29:10 +08:00
增加 鼠标悬停在目标序列代码上时,在代码矩阵中高亮相同的代码
修改 README中的演示动图
This commit is contained in:
parent
22e75d373a
commit
e78de86e8d
@ -30,6 +30,10 @@ namespace CodeMatrix
|
||||
{
|
||||
Location = new Point(codeQueue.Location.X, y)
|
||||
};
|
||||
codeTargets[i].HoverCodeEvent += (_, value) =>
|
||||
{
|
||||
codeMatrix.HighlightCode = value;
|
||||
};
|
||||
}
|
||||
|
||||
codeMatrix.HoverValueChangedEvent += (_, value) =>
|
||||
|
@ -26,6 +26,20 @@ namespace CodeMatrix
|
||||
}
|
||||
}
|
||||
public RectangleF CodeMatrixRect { get; private set; }
|
||||
private byte _HighlightCode;
|
||||
public byte HighlightCode
|
||||
{
|
||||
get => _HighlightCode;
|
||||
set
|
||||
{
|
||||
if (_HighlightCode != value)
|
||||
{
|
||||
_HighlightCode = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler<byte> HoverValueChangedEvent;
|
||||
public event EventHandler<byte> CodeSelectedEvent;
|
||||
|
||||
@ -154,6 +168,14 @@ namespace CodeMatrix
|
||||
brush = Styles.Default.CodeBrush;
|
||||
code = Matrix[col, row].ToString("X2");
|
||||
}
|
||||
if (HighlightCode != 0 && HighlightCode == Matrix[col, row])
|
||||
{
|
||||
e.Graphics.DrawRectangle(Styles.Default.SelectedCellBorderPen,
|
||||
CodeMatrixRect.X+cellOffset.X+1,
|
||||
CodeMatrixRect.Y+cellOffset.Y+1,
|
||||
CellSize.Width - 3,
|
||||
CellSize.Height - 3);
|
||||
}
|
||||
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+CodeMatrixRect.X, codeOffset.Y+cellOffset.Y+CodeMatrixRect.Y);
|
||||
|
@ -128,10 +128,46 @@ namespace CodeMatrix
|
||||
g.DrawString(codeStr, font, brush, codePoint);
|
||||
}
|
||||
|
||||
private int HoverIndex = -1;
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
|
||||
//HoverCodeEvent?.Invoke(this, _HoverCode);
|
||||
if (CurrState == State.Input)
|
||||
{
|
||||
int hoverIndex = -1;
|
||||
//Point currPoint = new Point(e.X - Padding.Left, e.Y - Padding.Top - CellMargin.Top);
|
||||
//if (currPoint.X >= 0 && currPoint.Y >= 0 && currPoint.Y < CellSize.Height)
|
||||
//{
|
||||
// int cellfullwidth = CellSize.Width + CellMargin.Horizontal;
|
||||
// int index = currPoint.X / cellfullwidth - OffsetIndex;
|
||||
// int offset = currPoint.X % cellfullwidth;
|
||||
// if (offset > CellMargin.Left && offset < cellfullwidth - CellMargin.Left)
|
||||
// {
|
||||
// if (index >= 0 && index < TargetLength)
|
||||
// {
|
||||
// hoverIndex = index;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Point currPoint = new Point(e.X - Padding.Left, e.Y - Padding.Top);
|
||||
if (currPoint.X >= 0 && currPoint.Y >= 0 && currPoint.Y < CellSize.Height)
|
||||
{
|
||||
int cellfullwidth = CellSize.Width + CellMargin.Horizontal;
|
||||
int index = currPoint.X / cellfullwidth - OffsetIndex;
|
||||
if (index >= 0 && index < TargetLength)
|
||||
{
|
||||
hoverIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
if (HoverIndex != hoverIndex)
|
||||
{
|
||||
HoverIndex = hoverIndex;
|
||||
if (HoverIndex >= 0)
|
||||
HoverCodeEvent?.Invoke(this, TargetCodes[HoverIndex]);
|
||||
else
|
||||
HoverCodeEvent?.Invoke(this, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
base.OnMouseMove(e);
|
||||
|
BIN
Images/CodeMatrix4.gif
Normal file
BIN
Images/CodeMatrix4.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
Loading…
Reference in New Issue
Block a user