Files
AntdUI/example/BallTest/BallLayeredForm.cs
2026-01-20 09:05:19 +00:00

387 lines
22 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AntdUI;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace BallTest
{
public partial class BallLayeredForm : ILayeredFormOpacity
{
#region
// 防误触阈值
private const int DRAG_THRESHOLD = 5;
// 拖动相关变量
private Point? dragStartPoint = null;
private bool isBeingDragged = false;
private bool isClick = false;
// 鼠标悬停状态
private bool isMouseOver = false;
/// <summary>
/// 菜单项列表 - 使用AntdUI控件
/// </summary>
private AntdUI.IContextMenuStripItem[] menuItems;
#region - 便
private Color _normalStartColor = Color.FromArgb(0, 128, 255); // 正常状态起始颜色
private Color _normalEndColor = Color.FromArgb(0, 75, 150); // 正常状态结束颜色
private Color _hoverStartColor = Color.FromArgb(0, 191, 255); // 悬停状态起始颜色
private Color _hoverEndColor = Color.FromArgb(0, 100, 200); // 悬停状态结束颜色
private Color _highlightColor1 = Color.White; // 主高光颜色
private int _highlightAlpha1 = 150; // 主高光透明度
private Color _highlightColor2 = Color.White; // 次高光颜色
private int _highlightAlpha2 = 100; // 次高光透明度
private Color _borderColor = Color.FromArgb(0, 50, 100); // 边框颜色
private int _borderAlpha = 120; // 边框透明度
private int _borderWidth = 2; // 边框宽度
// 颜色配置公共属性,便于外部自定义
// 添加DesignerSerializationVisibility特性以解决WFO1000警告
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public Color NormalStartColor
{
get => _normalStartColor;
set { _normalStartColor = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public Color NormalEndColor
{
get => _normalEndColor;
set { _normalEndColor = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public Color HoverStartColor
{
get => _hoverStartColor;
set { _hoverStartColor = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public Color HoverEndColor
{
get => _hoverEndColor;
set { _hoverEndColor = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public Color HighlightColor1
{
get => _highlightColor1;
set { _highlightColor1 = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public int HighlightAlpha1
{
get => _highlightAlpha1;
set { _highlightAlpha1 = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public Color HighlightColor2
{
get => _highlightColor2;
set { _highlightColor2 = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public int HighlightAlpha2
{
get => _highlightAlpha2;
set { _highlightAlpha2 = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public Color BorderColor
{
get => _borderColor;
set { _borderColor = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public int BorderAlpha
{
get => _borderAlpha;
set { _borderAlpha = value; Print(); }
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public int BorderWidth
{
get => _borderWidth;
set { _borderWidth = value; Print(); }
}
#endregion
#endregion
#region
public BallLayeredForm() : base(255)
{
// 设置默认大小和位置
int size = 200;
int x = Screen.PrimaryScreen.Bounds.Width / 2 - size / 2;
int y = Screen.PrimaryScreen.Bounds.Height / 2 - size / 2;
SetSize(size, size);
SetLocation(x, y);
// 同时设置Size和Location属性确保窗体正确显示
Size = new Size(size, size);
Location = new Point(x, y);
// 设置为最顶层窗口,确保能看到
TopMost = true;
// 初始化菜单项
InitializeMenuItems();
}
public override bool UFocus => false;
public override string name => nameof(BallLayeredForm);
// 初始化菜单项
private void InitializeMenuItems()
{
string svg_back = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M793 242H366v-74c0-6.7-7.7-10.4-12.9-6.3l-142 112c-4.1 3.2-4.1 9.4 0 12.6l142 112c5.2 4.1 12.9 0.4 12.9-6.3v-74h415v470H175c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h618c35.3 0 64-28.7 64-64V306c0-35.3-28.7-64-64-64z\"></path></svg>", svg_refresh = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M758.2 839.1C851.8 765.9 912 651.9 912 523.9 912 303 733.5 124.3 512.6 124 291.4 123.7 112 302.8 112 523.9c0 125.2 57.5 236.9 147.6 310.2 3.5 2.8 8.6 2.2 11.4-1.3l39.4-50.5c2.7-3.4 2.1-8.3-1.2-11.1-8.1-6.6-15.9-13.7-23.4-21.2-29.4-29.4-52.5-63.6-68.6-101.7C200.4 609 192 567.1 192 523.9s8.4-85.1 25.1-124.5c16.1-38.1 39.2-72.3 68.6-101.7 29.4-29.4 63.6-52.5 101.7-68.6C426.9 212.4 468.8 204 512 204s85.1 8.4 124.5 25.1c38.1 16.1 72.3 39.2 101.7 68.6 29.4 29.4 52.5 63.6 68.6 101.7 16.7 39.4 25.1 81.3 25.1 124.5s-8.4 85.1-25.1 124.5c-16.1 38.1-39.2 72.3-68.6 101.7-9.3 9.3-19.1 18-29.3 26L668.2 724c-4.1-5.3-12.5-3.5-14.1 3l-39.6 162.2c-1.2 5 2.6 9.9 7.7 9.9l167 0.8c6.7 0 10.5-7.7 6.3-12.9l-37.3-47.9z\"></path></svg>", svg_save = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M893.3 293.3L730.7 130.7c-7.5-7.5-16.7-13-26.7-16V112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V338.5c0-17-6.7-33.2-18.7-45.2zM384 184h256v104H384V184z m456 656H184V184h136v136c0 17.7 14.3 32 32 32h320c17.7 0 32-14.3 32-32V205.8l136 136V840z\" ></path><path d=\"M512 442c-79.5 0-144 64.5-144 144s64.5 144 144 144 144-64.5 144-144-64.5-144-144-144z m0 224c-44.2 0-80-35.8-80-80s35.8-80 80-80 80 35.8 80 80-35.8 80-80 80z\"></path></svg>", svg_print = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M820 436h-40c-4.4 0-8 3.6-8 8v40c0 4.4 3.6 8 8 8h40c4.4 0 8-3.6 8-8v-40c0-4.4-3.6-8-8-8z\"></path><path d=\"M852 332H732V120c0-4.4-3.6-8-8-8H300c-4.4 0-8 3.6-8 8v212H172c-44.2 0-80 35.8-80 80v328c0 17.7 14.3 32 32 32h168v132c0 4.4 3.6 8 8 8h424c4.4 0 8-3.6 8-8V772h168c17.7 0 32-14.3 32-32V412c0-44.2-35.8-80-80-80zM360 180h304v152H360V180z m304 664H360V568h304v276z m200-140H732V500H292v204H160V412c0-6.6 5.4-12 12-12h680c6.6 0 12 5.4 12 12v292z\"></path></svg>", svg_laptop = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M956.9 845.1L896.4 632V168c0-17.7-14.3-32-32-32h-704c-17.7 0-32 14.3-32 32v464L67.9 845.1C60.4 866 75.8 888 98 888h828.8c22.2 0 37.6-22 30.1-42.9zM200.4 208h624v395h-624V208z m228.3 608l8.1-37h150.3l8.1 37H428.7z m224 0l-19.1-86.7c-0.8-3.7-4.1-6.3-7.8-6.3H398.2c-3.8 0-7 2.6-7.8 6.3L371.3 816H151l42.3-149h638.2l42.3 149H652.7z\"></path></svg>", svg_qr = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M468 128H160c-17.7 0-32 14.3-32 32v308c0 4.4 3.6 8 8 8h332c4.4 0 8-3.6 8-8V136c0-4.4-3.6-8-8-8z m-56 284H192V192h220v220z\"></path><path d=\"M274 338h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zM468 548H136c-4.4 0-8 3.6-8 8v308c0 17.7 14.3 32 32 32h308c4.4 0 8-3.6 8-8V556c0-4.4-3.6-8-8-8z m-56 284H192V612h220v220z\"></path><path d=\"M274 758h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zM864 128H556c-4.4 0-8 3.6-8 8v332c0 4.4 3.6 8 8 8h332c4.4 0 8-3.6 8-8V160c0-17.7-14.3-32-32-32z m-32 284H612V192h220v220z\"></path><path d=\"M694 338h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zM888 548h-48c-4.4 0-8 3.6-8 8v134h-78V556c0-4.4-3.6-8-8-8H556c-4.4 0-8 3.6-8 8v332c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V644h78v102c0 4.4 3.6 8 8 8h190c4.4 0 8-3.6 8-8V556c0-4.4-3.6-8-8-8z\"></path><path d=\"M746 832h-48c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8zM888 832h-48c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z\"></path></svg>", svg_a = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M904 816H120c-4.4 0-8 3.6-8 8v80c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-80c0-4.4-3.6-8-8-8zM253.7 736h85c4.2 0 8-2.7 9.3-6.8l53.7-166h219.2l53.2 166c1.3 4 5 6.8 9.3 6.8h89.1c1.1 0 2.2-0.2 3.2-0.5 5.1-1.8 7.8-7.3 6-12.4L573.6 118.6c-1.4-3.9-5.1-6.6-9.2-6.6H462.1c-4.2 0-7.9 2.6-9.2 6.6L244.5 723.1c-0.4 1-0.5 2.1-0.5 3.2-0.1 5.3 4.3 9.7 9.7 9.7z m255.9-516.1h4.1l83.8 263.8H424.9l84.7-263.8z\"></path></svg>", svg_fy = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M140 188h584v164h76V144c0-17.7-14.3-32-32-32H96c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h544v-76H140V188z\"></path><path d=\"M414.3 256h-60.6c-3.4 0-6.4 2.2-7.6 5.4L219 629.4c-0.3 0.8-0.4 1.7-0.4 2.6 0 4.4 3.6 8 8 8h55.1c3.4 0 6.4-2.2 7.6-5.4L322 540h196.2L422 261.4c-1.3-3.2-4.3-5.4-7.7-5.4z m12.4 228h-85.5L384 360.2 426.7 484zM936 528H800v-93c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v93H592c-13.3 0-24 10.7-24 24v176c0 13.3 10.7 24 24 24h136v152c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V752h136c13.3 0 24-10.7 24-24V552c0-13.3-10.7-24-24-24zM728 680h-88v-80h88v80z m160 0h-88v-80h88v80z\"></path></svg>", svg_add = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M464 144H160c-8.8 0-16 7.2-16 16v304c0 8.8 7.2 16 16 16h304c8.8 0 16-7.2 16-16V160c0-8.8-7.2-16-16-16z m-52 268H212V212h200v200zM864 144H560c-8.8 0-16 7.2-16 16v304c0 8.8 7.2 16 16 16h304c8.8 0 16-7.2 16-16V160c0-8.8-7.2-16-16-16z m-52 268H612V212h200v200zM864 544H560c-8.8 0-16 7.2-16 16v304c0 8.8 7.2 16 16 16h304c8.8 0 16-7.2 16-16V560c0-8.8-7.2-16-16-16z m-52 268H612V612h200v200zM424 712H296V584c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v128H104c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h128v128c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V776h128c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z\"></path></svg>", svg_share = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M752 664c-28.5 0-54.8 10-75.4 26.7L469.4 540.8c1.7-9.3 2.6-19 2.6-28.8s-0.9-19.4-2.6-28.8l207.2-149.9C697.2 350 723.5 360 752 360c66.2 0 120-53.8 120-120s-53.8-120-120-120-120 53.8-120 120c0 11.6 1.6 22.7 4.7 33.3L439.9 415.8C410.7 377.1 364.3 352 312 352c-88.4 0-160 71.6-160 160s71.6 160 160 160c52.3 0 98.7-25.1 127.9-63.8l196.8 142.5c-3.1 10.6-4.7 21.8-4.7 33.3 0 66.2 53.8 120 120 120s120-53.8 120-120-53.8-120-120-120z m0-476c28.7 0 52 23.3 52 52s-23.3 52-52 52-52-23.3-52-52 23.3-52 52-52zM312 600c-48.5 0-88-39.5-88-88s39.5-88 88-88 88 39.5 88 88-39.5 88-88 88z m440 236c-28.7 0-52-23.3-52-52s23.3-52 52-52 52 23.3 52 52-23.3 52-52 52z\"></path></svg>", svg_about = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M716.3 313.8c19-18.9 19-49.7 0-68.6l-69.9-69.9 0.1 0.1c-18.5-18.5-50.3-50.3-95.3-95.2-21.2-20.7-55.5-20.5-76.5 0.5L80.9 474.2c-21.2 21.1-21.2 55.3 0 76.4L474.6 944c21.2 21.1 55.4 21.1 76.5 0l165.1-165c19-18.9 19-49.7 0-68.6-19-18.9-49.7-18.9-68.7 0l-125 125.2c-5.2 5.2-13.3 5.2-18.5 0L189.5 521.4c-5.2-5.2-5.2-13.3 0-18.5l314.4-314.2c0.4-0.4 0.9-0.7 1.3-1.1 5.2-4.1 12.4-3.7 17.2 1.1l125.2 125.1c19 19 49.8 19 68.7 0z\"></path><path d=\"M408.6 514.4a106.3 106.2 0 1 0 212.6 0 106.3 106.2 0 1 0-212.6 0Z\"></path><path d=\"M944.8 475.8L821.9 353.5c-19-18.9-49.8-18.9-68.7 0.1-19 18.9-19 49.7 0 68.6l83 82.9c5.2 5.2 5.2 13.3 0 18.5l-81.8 81.7c-19 18.9-19 49.7 0 68.6 19 18.9 49.7 18.9 68.7 0l121.8-121.7c21.1-21.1 21.1-55.2-0.1-76.4z\"></path></svg>";
menuItems = new AntdUI.IContextMenuStripItem[]
{
new AntdUI.ContextMenuStripItem("返回", "Alt+向左键").SetIcon(svg_back),
new AntdUI.ContextMenuStripItem("刷新", "Ctrl+R").SetIcon(svg_refresh),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("另存为", "Ctrl+S").SetIcon(svg_save),
new AntdUI.ContextMenuStripItem("打印", "Ctrl+P").SetIcon(svg_print),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("发送标签页到你的设备").SetIcon(svg_laptop),
new AntdUI.ContextMenuStripItem("为此页面创建QR代码").SetIcon(svg_qr),
new AntdUI.ContextMenuStripItem("大声朗读", "Ctrl+Shift+U").SetIcon(svg_a),
new AntdUI.ContextMenuStripItem("翻译为 中文(简体)").SetIcon(svg_fy),
new AntdUI.ContextMenuStripItem("将页面添加到集锦").SetIcon(svg_add).SetSub(
new AntdUI.ContextMenuStripItem("返回", "Alt+向左键").SetIcon(svg_back).SetSub(
new AntdUI.ContextMenuStripItem("返回", "Alt+向左键").SetIcon(svg_back),
new AntdUI.ContextMenuStripItem("刷新", "Ctrl+R").SetIcon(svg_refresh),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("另存为", "Ctrl+S").SetIcon(svg_save),
new AntdUI.ContextMenuStripItem("打印", "Ctrl+P").SetIcon(svg_print)
),
new AntdUI.ContextMenuStripItem("刷新", "Ctrl+R").SetIcon(svg_refresh),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("另存为", "Ctrl+S").SetIcon(svg_save),
new AntdUI.ContextMenuStripItem("打印", "Ctrl+P").SetIcon(svg_print)
),
new AntdUI.ContextMenuStripItemDivider(),
new AntdUI.ContextMenuStripItem("共享").SetIcon(svg_share),
new AntdUI.ContextMenuStripItem("关于").SetIcon(svg_about)
};
}
#endregion
#region
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
// 窗口句柄创建后立即渲染
Print();
}
public override Bitmap? PrintBit()
{
// 获取目标区域大小
var rect = TargetRect;
var rectXY = TargetRectXY;
// 创建一个与目标区域大小相同的位图使用32位ARGB格式
var bitmap = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (var g = Graphics.FromImage(bitmap))
{
// 设置高质量绘图选项
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
// 清除背景(透明)
g.Clear(Color.Transparent);
// 绘制渐变圆球
int centerX = rect.Width / 2;
int centerY = rect.Height / 2;
int radius = Math.Min(centerX, centerY) - 10;
// 根据鼠标状态选择渐变颜色
Color startColor = isMouseOver ? _hoverStartColor : _normalStartColor;
Color endColor = isMouseOver ? _hoverEndColor : _normalEndColor;
// 使用线性渐变,从左上角到右下角
using (var gradientBrush = new LinearGradientBrush(
new Point(centerX - radius, centerY - radius),
new Point(centerX + radius, centerY + radius),
startColor,
endColor))
{
// 绘制圆形主体
g.FillEllipse(gradientBrush, centerX - radius, centerY - radius, radius * 2, radius * 2);
// 添加多层次高光,增强立体感
// 主高光左上角明亮的白色椭圆形高光参考图片2
using (var highlightBrush1 = new SolidBrush(Color.FromArgb(_highlightAlpha1, _highlightColor1)))
{
int highlightWidth = radius * 3 / 2;
int highlightHeight = radius * 3 / 4;
g.FillEllipse(highlightBrush1,
centerX - highlightWidth / 2,
centerY - highlightHeight / 2 - radius / 6,
highlightWidth, highlightHeight);
}
// 次高光:中心位置的白色高亮区
using (var highlightBrush2 = new SolidBrush(Color.FromArgb(_highlightAlpha2, _highlightColor2)))
{
int centerHighlightSize = radius * 2 / 3;
g.FillEllipse(highlightBrush2,
centerX - centerHighlightSize / 2,
centerY - centerHighlightSize / 2,
centerHighlightSize, centerHighlightSize);
}
// 调整边框:使用深蓝色边框,更精致
using (var pen = new Pen(Color.FromArgb(_borderAlpha, _borderColor), _borderWidth))
{
g.DrawEllipse(pen, centerX - radius, centerY - radius, radius * 2, radius * 2);
}
}
}
return bitmap;
}
protected override void OnMouseEnter(EventArgs e)
{
isMouseOver = true;
Print();
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
isMouseOver = false;
Print();
base.OnMouseLeave(e);
}
// 鼠标按下事件,开始拖动或显示右键菜单
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
isClick = true;
dragStartPoint = e.Location;
// 更改光标样式
Cursor = Cursors.SizeAll;
}
else if (e.Button == MouseButtons.Right)
{
// 获取鼠标在屏幕上的位置
Point screenPos = PointToScreen(e.Location);
// 显示AntdUI右键菜单
var config = new AntdUI.ContextMenuStrip.Config(new AntdUI.Target(this), item =>
{
// 处理菜单项点击事件
//switch (item.Text)
//{
// case "返回":
// // 移动功能已通过拖动实现
// break;
// case "刷新":
// // IClose(true);
// break;
// case "关于":
// break;
//}
AntdUI.Notification.open(this, item.Text, "AntdUI 作者人不错", TAlignFrom.Top);
}, menuItems)
{
Location = screenPos, // 设置菜单位置为当前鼠标位置
TopMost = true
};
AntdUI.ContextMenuStrip.open(config);
}
}
// 鼠标移动事件,处理拖动
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
// 处理拖动逻辑
if (dragStartPoint.HasValue)
{
int deltaX = e.X - dragStartPoint.Value.X;
int deltaY = e.Y - dragStartPoint.Value.Y;
// 检查是否超过防误触阈值
if (!isBeingDragged && (Math.Abs(deltaX) > DRAG_THRESHOLD || Math.Abs(deltaY) > DRAG_THRESHOLD))
{
isBeingDragged = true;
isClick = false;
}
if (isBeingDragged)
{
// 更新位置
var rect = TargetRect;
int newX = rect.X + deltaX;
int newY = rect.Y + deltaY;
// 设置新位置
SetLocation(newX, newY);
Location = new Point(newX, newY);
// 使用PrintCache优化拖动性能
PrintCache();
}
}
}
// 鼠标释放事件,结束拖动
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
// 恢复默认光标
Cursor = DefaultCursor;
// 处理点击事件
if (isClick && !isBeingDragged)
{
// 左键点击关闭窗口
if (e.Button == MouseButtons.Left)
{
//IClose(true);
}
}
// 重置拖动状态
dragStartPoint = null;
isBeingDragged = false;
isClick = false;
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
// 右键点击事件已由ContextMenuStrip处理
}
#endregion
}
}