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

简介: 代码 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窗体的,其具体原理就是分层窗体....
992 0
Winform控件优化之实现无锯齿的圆角窗体(或任意图形的无锯齿丝滑的窗体或控件)【借助LayeredWindow】
|
算法 API C#
Winform控件优化之圆角按钮【各种实现中的推荐做法】(下)
最终优化实现ButtonPro按钮(继承自Button),既提供Button原生功能,又提供扩展功能,除了圆角以外,还实现了圆形、圆角矩形的脚尖效果、边框大小和颜色、背景渐变颜色...
1227 0
Winform控件优化之圆角按钮【各种实现中的推荐做法】(下)
|
C# 图形学 Windows
Winform控件优化之圆角按钮【各种实现中的推荐做法】(上)
Windows 11下所有控件已经默认采用圆角,其效果更好、相对有着更好的优化...尝试介绍很常见的圆角效果,通过重写控件的OnPaint方法实现绘制,并在后面进一步探索对应的优化和可能的问题
987 0
Winform控件优化之圆角按钮【各种实现中的推荐做法】(上)
|
API 数据安全/隐私保护
VB编程:无标题栏窗体移动和自定义鼠标样式
VB编程:无标题栏窗体移动和自定义鼠标样式
203 0
|
C#
WPF窗体隐藏鼠标光标的方法
原文:WPF窗体隐藏鼠标光标的方法 要引用 System.Windows.Input;   Mouse.OverrideCursor = Cursors.
1566 0