实现当就绪状态时鼠标移到区域内填充半透明色的功能
This commit is contained in:
@@ -31,6 +31,7 @@ namespace JoyD.Windows.CS
|
|||||||
private int _regionCounter = 0;
|
private int _regionCounter = 0;
|
||||||
// 叠加层图像 - 用于存储已完成绘制的矩形
|
// 叠加层图像 - 用于存储已完成绘制的矩形
|
||||||
private Image _rectangleOverlayImage = null;
|
private Image _rectangleOverlayImage = null;
|
||||||
|
private int _hoveredRegionIndex = -1; // 当前悬停的区域索引(-1表示没有悬停在任何区域上)
|
||||||
|
|
||||||
public Setting()
|
public Setting()
|
||||||
{
|
{
|
||||||
@@ -167,7 +168,7 @@ namespace JoyD.Windows.CS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 鼠标移动事件 - 更新矩形大小
|
/// 鼠标移动事件 - 更新矩形大小或检测鼠标悬停区域
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void PicBoxTemp_MouseMove(object sender, MouseEventArgs e)
|
private void PicBoxTemp_MouseMove(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -184,6 +185,29 @@ namespace JoyD.Windows.CS
|
|||||||
|
|
||||||
picBoxTemp.Invalidate();
|
picBoxTemp.Invalidate();
|
||||||
}
|
}
|
||||||
|
else if (!_isDrawingMode && !_isDrawing) // 就绪状态
|
||||||
|
{
|
||||||
|
// 将鼠标坐标转换为图像坐标
|
||||||
|
Point imagePoint = ControlPointToImagePoint(e.Location);
|
||||||
|
|
||||||
|
// 检查鼠标是否在某个区域内
|
||||||
|
int newHoveredRegionIndex = -1;
|
||||||
|
foreach (RegionInfo region in _drawnRectangles)
|
||||||
|
{
|
||||||
|
if (region.ImageRectangle.Contains(imagePoint))
|
||||||
|
{
|
||||||
|
newHoveredRegionIndex = region.Index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果悬停的区域发生变化,更新并触发重绘
|
||||||
|
if (newHoveredRegionIndex != _hoveredRegionIndex)
|
||||||
|
{
|
||||||
|
_hoveredRegionIndex = newHoveredRegionIndex;
|
||||||
|
picBoxTemp.Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -362,6 +386,7 @@ namespace JoyD.Windows.CS
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 绘制事件 - 显示矩形框(实现图像合并机制)
|
/// 绘制事件 - 显示矩形框(实现图像合并机制)
|
||||||
/// 处理叠加层图像的缩放,确保与控件尺寸匹配
|
/// 处理叠加层图像的缩放,确保与控件尺寸匹配
|
||||||
|
/// 实现鼠标悬停区域填充半透明色功能
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void PicBoxTemp_Paint(object sender, PaintEventArgs e)
|
private void PicBoxTemp_Paint(object sender, PaintEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -378,6 +403,27 @@ namespace JoyD.Windows.CS
|
|||||||
e.Graphics.DrawImage(_rectangleOverlayImage, destRect, 0, 0, _rectangleOverlayImage.Width, _rectangleOverlayImage.Height, GraphicsUnit.Pixel);
|
e.Graphics.DrawImage(_rectangleOverlayImage, destRect, 0, 0, _rectangleOverlayImage.Width, _rectangleOverlayImage.Height, GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 绘制悬停区域的半透明填充(就绪状态)
|
||||||
|
if (!_isDrawingMode && _hoveredRegionIndex != -1)
|
||||||
|
{
|
||||||
|
// 查找当前悬停的区域
|
||||||
|
RegionInfo hoveredRegion = _drawnRectangles.FirstOrDefault(r => r.Index == _hoveredRegionIndex);
|
||||||
|
if (hoveredRegion != null)
|
||||||
|
{
|
||||||
|
// 将图像坐标转换为控件坐标
|
||||||
|
Rectangle controlRectangle = ImageRectangleToControlRectangle(hoveredRegion.ImageRectangle);
|
||||||
|
|
||||||
|
// 创建半透明的填充颜色(使用区域的颜色,但设置透明度)
|
||||||
|
Color semiTransparentColor = Color.FromArgb(100, hoveredRegion.Color);
|
||||||
|
|
||||||
|
// 填充半透明矩形
|
||||||
|
using (SolidBrush brush = new SolidBrush(semiTransparentColor))
|
||||||
|
{
|
||||||
|
e.Graphics.FillRectangle(brush, controlRectangle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 再绘制临时矩形(当前正在绘制的矩形,使用控件坐标)
|
// 再绘制临时矩形(当前正在绘制的矩形,使用控件坐标)
|
||||||
if (!_currentRectangle.IsEmpty && _isDrawingMode && _isDrawing)
|
if (!_currentRectangle.IsEmpty && _isDrawingMode && _isDrawing)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user