Categories > Coding > C# >
Smooth Drag [WinForms]
Posted
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace smoothdrag
{
public partial class Form1 : Form
{
private Point mouseDownPoint = Point.Empty;
private Point targetLocation = Point.Empty;
private Timer moveTimer = new Timer();
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.ResizeRedraw, true);
moveTimer.Interval = 10;
moveTimer.Tick += MoveTimer_Tick;
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
{
if (e.Button == MouseButtons.Left)
{
mouseDownPoint = e.Location;
targetLocation = this.Location;
moveTimer.Start();
}
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
{
if (e.Button == MouseButtons.Left)
{
targetLocation = new Point(this.Location.X + e.X - mouseDownPoint.X, this.Location.Y + e.Y - mouseDownPoint.Y);
}
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
{
if (e.Button == MouseButtons.Left)
{
moveTimer.Stop();
}
}
}
private void MoveTimer_Tick(object sender, EventArgs e)
{
int dx = (targetLocation.X - this.Location.X) / 10;
int dy = (targetLocation.Y - this.Location.Y) / 10;
this.Location = new Point(this.Location.X + dx, this.Location.Y + dy);
}
}
}
Showcase:
https://cdn.discordapp.com/attachments/967085236015992842/1137411251404812438/2023-08-05_17-37-05.mp4
Cancel
Post
https://cdn.discordapp.com/attachments/968557692639666267/1139574673630318632/lodlk.png
https://cdn.discordapp.com/attachments/921008361342902274/1144217307170742363/Bez_tytuu692.png
Replied
why the hell would you want the window to be 2 seconds behind where your current cursor is
Cancel
Post
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
Replied
Whats the point of this most people would just get annoyed by it
Comments
Mikrofalufka 5 Reputation
Commented
Idk bro
/charss
Cancel
Post
Discord Contact : fatty__joe
Replied
this is the exact result of my old laptop trying to drag windows
Cancel
Post
https://media.discordapp.net/attachments/1137455283690541067/1146437345319596102/Group_1_16.png
Replied
"Smooth drag" lmfao
Cancel
Post
Discord : Doctor Doom#0550
Replied
This aint worth it bro. Its jst a waste of time think about it we losin two secounds bruv
Cancel
Post
https://cdn.discordapp.com/attachments/661621789591470090/1013919752294498314/Untitled_1366_768_px_1546_202_px_2.gif
Replied
Why smooth drag and delay the position? I dont get it
Cancel
Post
https://cdn.discordapp.com/attachments/995469995742068832/1073019970012848228/Untitled39_20220604185345.png
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Comments
Pluto_Guy 30 Reputation
Commented
Why not /charsss
0
RealRealNik 39 Reputation
Commented
@Pluto_Guy its just annoying
0