Files
PDFPatcher/App/Functions/Editor/Parts/MousePositionInfoHandler.cs
2026-10-12 16:49:14 +08:00

45 lines
1.1 KiB
C#

using System;
using System.Windows.Forms;
using PDFPatcher.Common;
namespace PDFPatcher.Functions.Editor.Parts;
/// <summary>
/// 在状态栏显示鼠标所在位置的页面坐标和文本。
/// </summary>
sealed class MousePositionInfoHandler
{
readonly Label _Label;
readonly ViewerControl _ViewerBox;
public MousePositionInfoHandler(Label label, ViewerControl viewerBox) {
_Label = label;
_ViewerBox = viewerBox;
viewerBox.MouseMove += HandleViewerBoxMouseMove;
}
void HandleViewerBoxMouseMove(object sender, MouseEventArgs e) {
if (_ViewerBox.FirstPage == 0) {
return;
}
var l = e.Location;
var p = _ViewerBox.TransposeClientToPagePosition(l.X, l.Y);
if (p.Page == 0) {
return;
}
var ti = _ViewerBox.FindTextLines(p);
var t = ti.ToString();
_Label.Text = string.Concat("页面:",
p.Page,
"/",
_ViewerBox.TotalPageCount.ToText(),
"; 位置:",
Math.Round(p.PageX, 2),
" * ",
Math.Round(p.PageY, 2),
ti.Spans.HasContent() ? String.Concat("; 字体:", String.Join(";", ti.GetFontNames()), " ", ti.Spans[0].Size) : null,
t != null ? "; 文本:" : null,
t);
}
}