Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Visual Basic Programming › [Help] Movable Buttons[Solved]

[Help] Movable Buttons[Solved]

Posts 1–11 of 11 · Page 1 of 1
OM
omghacker
[Help] Movable Buttons[Solved]
Okay, so I want to let a user be able to move buttons in a form whenever he clicks it and holds the mouse.
I did some research and expiremented but I didn't found anything usefull.
Can anyone please help me? =3
#1 · 16y ago
consca
consca
Ok heres some code off the top of my head.
1 First make a new timer
2 then disable the timer
3 Double click the timer
4 Type this code:
Code:
button1.location = new point(cursor.position.x, cursor.position.y)
5 Now click the button and go to your events tab and find mousedown
6 in the mousedown code type this:
Code:
timer1.enabled = true
7 Now find the mouseup code and type this:
Code:
Timer1.enabled = false
Its not the best code but it works. if you need questions ask!
#2 · 15y ago
Imported
Imported
Quote Originally Posted by consca View Post
Ok heres some code off the top of my head.
1 First make a new timer
2 then disable the timer
3 Double click the timer
4 Type this code:
Code:
button1.location = new point(cursor.position.x, cursor.position.y)
5 Now click the button and go to your events tab and find mousedown
6 in the mousedown code type this:
Code:
timer1.enabled = true
7 Now find the mouseup code and type this:
Code:
Timer1.enabled = false
Its not the best code but it works. if you need questions ask!
That won't work as the "Cursor.Position" is relative to your whole screen, while the button's location is only relative to the form. 1 Sec
#3 · 15y ago
consca
consca
Yeah, as i said.. at the top of my head. rymes

Button1.Location = New Point(Cursor.Position.X - Me.Location.X, Cursor.Position.Y - Me.Location.Y)

Do that its a fix


EDIITT!!!!!!

Real fix. works perfect!

Button1.Location = New Point(Cursor.Position.X - Me.Location.X - Button1.Size.Width / 2, Cursor.Position.Y - Me.Location.Y - Button1.Height * 1.5)'Adjust the 1.5 based on the size of the button
#4 · edited 15y ago · 15y ago
cosconub
cosconub
ok, here is an EVEN EPIC EASYER CODE

by ImMortAL-
Code:
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
        Xpos = Cursor.Position.X - Button1.Location.X
        Ypos = Cursor.Position.Y - Button1.Location.Y
    End Sub

    Private Sub Button16_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Pos = MousePosition
            Pos.X = Pos.X - Xpos
            Pos.Y = Pos.Y - Ypos
            Button1.Location = Pos

        End If
to use this code read this

http://www.mpgh.net/forum/33-visual-...rum-r-c-p.html
#5 · 15y ago
Imported
Imported
I find this is a lot smoother:

Variables
[php]
#Region "ButtonVars"
Dim ix, iy As Integer
Dim pX, pY As Integer
Dim isDragging As Boolean
#End Region
[/php]

Moving:
[php]
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
isDragging = True
ix = Cursor.Position.X - Me.Location.X - Button1.Location.X
iy = Cursor.Position.Y - Me.Location.Y - Button1.Location.Y
End Sub

Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
If isDragging Then
Dim pp As New Point(Cursor.Position.X - Me.Location.X - ix, Cursor.Position.Y - Me.Location.Y - iy)
Button1.Location = New Point(pp)
End If
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
isDragging = False
End Sub
[/php]
#6 · 15y ago
OM
omghacker
Thanks for the replies guys
I'll try some of them later on today ^^
Love MPGH :3
#7 · 15y ago
Imported
Imported
Quote Originally Posted by omghacker View Post
Thanks for the replies guys
I'll try some of them later on today ^^
Love MPGH :3
Really, well there is a button for it.
#8 · 15y ago
NextGen1
NextGen1
I am glad this is solved, and will be marked as such, however, Doesn't everyone know that MSDN is loaded with basic codes (like this, as it was the intentions of the designers) ,. In either case, /marked solved.
#9 · 15y ago
Jason
Jason
Quote Originally Posted by NextGen1 View Post
I am glad this is solved, and will be marked as such, however, Doesn't everyone know that MSDN is loaded with basic codes (like this, as it was the intentions of the designers) ,. In either case, /marked solved.
I think MSDN scares people (like me). I don't like their social forum thingo either, it has a really messed up layout. It's pretty much a last resort .
#10 · 15y ago
NextGen1
NextGen1
Meh, Memorize what you can, common sense and intellesence ;p
#11 · 15y ago
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

  • [Help] Hide Button [Solved]By Hahne in Visual Basic Programming
    3Last post 16y ago
  • [Help]Click Image Button[Solved]By ppl2pass in Visual Basic Programming
    12Last post 16y ago
  • [Help]Change Button Text[Solved]By [PA]nts in Visual Basic Programming
    7Last post 16y ago
  • [Help]Open link click of button[Solved]By iFrank1 in Visual Basic Programming
    7Last post 16y ago
  • [Help]Treeview Search Button[Solved]By ModelCookie2 in Visual Basic Programming
    6Last post 15y ago

Tags for this Thread

None