Movable controls but read ...
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts
Page 1 of 1
How do i make movable controls like
dim btn as new button
make the btn movable?
dim btn as new button
make the btn movable?
Hello,
If your adding the controls dynamically then you will need to add event handlers for them manually.
To add a moveable button you can try this. First under "Public Class Form" add this:
If your adding the controls dynamically then you will need to add event handlers for them manually.
To add a moveable button you can try this. First under "Public Class Form" add this:
Code: Select all
Then add this code wherever you want to create your button, like at form load or a button click or something:Dim a
Dim b
Dim capt = 0
Code: Select all
Then add these event handlers within your main code:Dim btn As New Button
btn.Size = New Size(100, 100) 'CHANGE TO THE HEIGHT AND WIDTH OF YOUR BUTTON
btn.Location = New Point(100, 100) 'CHANGE TO THE LOCATION FOR IT TO BE CREATED
AddHandler btn.MouseDown, AddressOf btn_Down
AddHandler btn.MouseUp, AddressOf btn_Up
AddHandler btn.MouseMove, AddressOf btn_Move
Me.Controls.Add(btn)
Code: Select all
That should do it cooll; Private Sub btn_Down(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
a = e.X
b = e.Y
capt = 1
End Sub
Private Sub btn_Up(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
CType(sender, Button).Location = New Point(CType(sender, Button).Location.X + (e.X - a), CType(sender, Button).Location.Y + (e.Y - b))
capt = 0
End Sub
Private Sub btn_Move(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If capt = 1 Then
CType(sender, Button).Location = New Point(CType(sender, Button).Location.X + (e.X - a), CType(sender, Button).Location.Y + (e.Y - b))
End If
End Sub
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023