手写代码实现窗体的拖动效果

简介: 代码 public partial class Form1 : Form {private Point oldPoint = new Point(0,0);public Form1() { InitializeComponent(); ...
img_1c53668bcee393edac0d7b3b3daff1ae.gif img_405b18b4b6584ae338e0f6ecaf736533.gif 代码
 
  
public partial class Form1 : Form
{
private Point oldPoint = new Point( 0 , 0 );
public Form1()
{
InitializeComponent();
}

private void linkLabel1_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e)
{
this .Close();
}

private void linkLabel2_MouseDown( object sender, MouseEventArgs e)
{
oldPoint.X
= Cursor.Position.X;
oldPoint.Y
= Cursor.Position.Y;
}

private void linkLabel2_MouseMove( object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int offset_x = Cursor.Position.X - oldPoint.X;
int offset_y = Cursor.Position.Y - oldPoint.Y;
this .Location = new Point( this .Location.X + offset_x, this .Location.Y + offset_y);
oldPoint.X
= Cursor.Position.X;
oldPoint.Y
= Cursor.Position.Y;
}
}
}

 

目录
相关文章
|
算法 Windows
Winform控件优化之实现无锯齿的圆角窗体(或任意图形的无锯齿丝滑的窗体或控件)【借助LayeredWindow】
在一般能搜到的所有实现圆角窗体的示例中,都有着惨不忍睹的锯齿...而借助于Layered Windows,是可以实现丝滑无锯齿效果的Form窗体的,其具体原理就是分层窗体....
1866 0
Winform控件优化之实现无锯齿的圆角窗体(或任意图形的无锯齿丝滑的窗体或控件)【借助LayeredWindow】
|
25天前
|
图形学
Unity UGUI实现鼠标拖动图片
在 Unity UGUI 中实现鼠标拖动图片功能,主要涉及事件检测、坐标转换和物体位置更新。根据鼠标移动量更新图片位置。代码示例展示了如何通过这些步骤实现拖动效果。
|
8月前
|
开发框架 数据可视化 C#
第一次机房收费系统之显示全部窗体
第一次机房收费系统之显示全部窗体
49 0
|
C#
WPF控件获得焦点时去除虚线框
原文:WPF控件获得焦点时去除虚线框
1917 0
|
JavaScript 前端开发 Python
|
图形学
unity3d UGUI的down与up弹窗,松开时关闭窗口处理机制
挂载到对象即可,然后注册回调做down和up的处理 using UnityEngine; using UnityEngine.EventSystems; public class PushListener : MonoBehaviour,IPointe...
826 0