Categories > Coding > C# >

Smooth Drag [WinForms]

Posts: 215

Threads: 24

Joined: Jun, 2023

Reputation: 5

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);
        }
    }
}

 

GITHUB

 

Showcase: 

https://cdn.discordapp.com/attachments/967085236015992842/1137411251404812438/2023-08-05_17-37-05.mp4

  • 0

https://cdn.discordapp.com/attachments/968557692639666267/1139574673630318632/lodlk.png

https://cdn.discordapp.com/attachments/921008361342902274/1144217307170742363/Bez_tytuu692.png

SeizureSalad

i love femboys

Posts: 1157

Threads: 79

Joined: Mar, 2021

Reputation: 40

Replied

why the hell would you want the window to be 2 seconds behind where your current cursor is

Comments

Pluto_Guy 29 Reputation

Commented

Why not /charsss

  • 0

RealRealNik 43 Reputation

Commented

@Pluto_Guy its just annoying

 

  • 0

  • 0

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Huddy

ScriptVault coming soon

vip

Posts: 317

Threads: 18

Joined: Apr, 2022

Reputation: 22

Replied

Whats the point of this most people would just get annoyed by it 

Comments

Mikrofalufka 5 Reputation

Commented

Idk bro

/charss

  • 0

  • 0

Discord Contact : fatty__joe

Kxhu

C# & Lua enjoyer

Posts: 290

Threads: 23

Joined: Dec, 2022

Reputation: 12

Replied

bro got a little too inspired

Comments

Mikrofalufka 5 Reputation

Commented

i just got no ideas

  • 0

  • 0

Thx for reps everyone: https://forum.wearedevs.net/profile/reputation?uid=90498

Posts: 17

Threads: 3

Joined: Aug, 2023

Reputation: -11

Replied

this is the exact result of my old laptop trying to drag windows

  • 1

https://media.discordapp.net/attachments/1137455283690541067/1146437345319596102/Group_1_16.png

Posts: 2097

Threads: 10

Joined: Sep, 2020

Reputation: 62

Replied

"Smooth drag" lmfao

  • 0

Discord : Doctor Doom#0550

pepsi

PePsIDeveloper

vip

Posts: 309

Threads: 6

Joined: Apr, 2021

Reputation: 16

Replied

This aint worth it bro. Its jst a waste of time think about it we losin two secounds bruv

  • 0

https://cdn.discordapp.com/attachments/661621789591470090/1013919752294498314/Untitled_1366_768_px_1546_202_px_2.gif

Zera

Casual Femboy Agent

vip

Posts: 1552

Threads: 39

Joined: Mar, 2020

Reputation: 42

Replied

Why smooth drag and delay the position? I dont get it

  • 0

https://cdn.discordapp.com/attachments/995469995742068832/1073019970012848228/Untitled39_20220604185345.png

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )