Solved

VB.net Allowing a userto drag a control to a different part of a form

Posted on 2013-05-31
2
294 Views
Last Modified: 2013-06-04
Hi

I have a VB.net app where I would like a user to be able to re-position
any control on a Windows form. Is it possible to allow this and then get
information about the new position?
0
Comment
Question by:murbro
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39210417
Yes it's possible. You simply need to handle the MouseDown, MouseUp, and MouseMove events. You can use MouseUp to get the information about the new position.

e.g.

Public Class Form1
    Private isControlDown As Boolean = False
    Private allowMove As Boolean = False

    Private Sub TextBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseDown
        Me.allowMove = Me.isControlDown
    End Sub

    Private Sub TextBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseMove
        If Me.allowMove Then
            Me.TextBox1.Location = Me.PointToClient(Me.TextBox1.PointToScreen(e.Location))
        End If
    End Sub

    Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
        Me.isControlDown = e.Control
    End Sub

    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        Me.isControlDown = e.Control
    End Sub

    Private Sub TextBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseUp
        Me.allowMove = False
    End Sub
End Class

Open in new window


I added a test for the Control key being down before the control is permitted to move. You don't have to do this, and you can change it to any key you like.
0
 

Author Closing Comment

by:murbro
ID: 39218834
Thanks very much
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question