C#实现随鼠标移动窗体实例
程序员文章站
2023-12-16 16:45:58
本文实例讲述了c#实现随鼠标移动窗体的方法,分享给大家供大家参考。
具体实现方法如下:
private void mainform_load(object se...
本文实例讲述了c#实现随鼠标移动窗体的方法,分享给大家供大家参考。
具体实现方法如下:
private void mainform_load(object sender, eventargs e) { //绑定事件 mousemove += form_mousemove; mousedown += form_mousedown; } private point _mousepoint; private void form_mousemove(object sender, mouseeventargs e) { if (e.button == mousebuttons.left) { top = mouseposition.y - _mousepoint.y; left = mouseposition.x - _mousepoint.x; } } private void form_mousedown(object sender, mouseeventargs e) { if (e.button == mousebuttons.left) { _mousepoint.x = e.x; _mousepoint.y = e.y; } }
如果窗体有标题则改为:
top -= systeminformation.captionheight;
如果有边框则改为:
top -= systeminformation.formbordersize.height left -= systeminformation.formbordersize.width
希望本文所述对大家的c#程序设计有所帮助