Click here to Skip to main content
15,895,740 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: error with decalre function Pin
progload31-Mar-06 7:44
progload31-Mar-06 7:44 
QuestionControl Tabs Pin
Leavashni30-Mar-06 19:56
Leavashni30-Mar-06 19:56 
Questionport knocking Pin
joby224330-Mar-06 19:53
joby224330-Mar-06 19:53 
AnswerRe: port knocking Pin
Dave Kreskowiak31-Mar-06 5:09
mveDave Kreskowiak31-Mar-06 5:09 
QuestionMoving any Control (For instance BUTTON) on the Form's surface Pin
Mr. Arfan Qadir30-Mar-06 18:52
Mr. Arfan Qadir30-Mar-06 18:52 
AnswerRe: Moving any Control (For instance BUTTON) on the Form's surface Pin
sathish s30-Mar-06 21:02
sathish s30-Mar-06 21:02 
GeneralRe: Moving any Control (For instance BUTTON) on the Form's surface Pin
Dave Kreskowiak31-Mar-06 5:05
mveDave Kreskowiak31-Mar-06 5:05 
AnswerRe: Moving any Control (For instance BUTTON) on the Form's surface Pin
Dave Kreskowiak31-Mar-06 5:03
mveDave Kreskowiak31-Mar-06 5:03 
There's no option to make a control movable at runtime. You actually have to make your own version of the button and add support to move the control around while the mouse button is held down. There's actually quite a bit of code that goes into this. Too much to post into a forum message.

Basically, you create a new class, inheriting from Button. Add a couple of private fields to track where in the button the mouse is being held down (a Point instance works), and whether the control is being moved (Boolean).

Once that's done, the rest kind of falls into place if you think about it. Handle the button's MouseDown event to set the Moving flag to True and get the coordinates of the mouse point inside the button and save them in your private field. In the buttons MouseUp event, just set the Moving flag to False.

The MouseMove event is logically simple, but a little complicated in code. You need to calculate the new position of the control using the mouse position with respect to the buttons parent container, not the button itself. Then it's just a matter of a little math...
Public Class MovableButton
    Inherits Button
 
    Private _CursorOffset As Point
    Private _Moving As Boolean
.
.
.
    Private Sub MovableButton_MouseMove(blah, blah) Handles MyBase.MouseMove
        If _Moving Then
            Dim clientPosition As Point = MyBase.Parent.PointToClient(Cursor.Position)
            MyBase.Location = New Point(clientPosition.X - _CursorOffset.X, _
                                        clientPosition.Y - _CursorOffset.Y)
        End If
    End Sub

There's obviously more to this code, specially when you consider design-time requirements and any other "options" you want to put on this button, like picking which key combination to hold down to move the button.


RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

QuestionSimplify your life with Object Binding Pin
Iqbal M Khan30-Mar-06 18:50
Iqbal M Khan30-Mar-06 18:50 
QuestionClear XML Element Pin
nitin_ion30-Mar-06 18:40
nitin_ion30-Mar-06 18:40 
QuestionFile transfer help Pin
Mega130-Mar-06 17:27
Mega130-Mar-06 17:27 
AnswerRe: File transfer help Pin
hbk72331-Mar-06 1:35
hbk72331-Mar-06 1:35 
GeneralRe: File transfer help Pin
Mega131-Mar-06 4:08
Mega131-Mar-06 4:08 
GeneralRe: File transfer help Pin
Chatura Dilan31-Mar-06 17:43
Chatura Dilan31-Mar-06 17:43 
QuestionLoad html page in VB.NET Pin
lucdt30-Mar-06 17:03
lucdt30-Mar-06 17:03 
AnswerRe: Load html page in VB.NET Pin
sathish s30-Mar-06 20:02
sathish s30-Mar-06 20:02 
Questionnull value - datetimepicker checked property Pin
VaLynna30-Mar-06 16:36
VaLynna30-Mar-06 16:36 
AnswerRe: null value - datetimepicker checked property Pin
sathish s30-Mar-06 19:05
sathish s30-Mar-06 19:05 
QuestionHowto:Transfer or show display Excel data into listbox with VB.NET Pin
jikadawe30-Mar-06 16:34
jikadawe30-Mar-06 16:34 
Questionview video Pin
vivayor kong30-Mar-06 15:49
vivayor kong30-Mar-06 15:49 
AnswerRe: view video Pin
Dave Kreskowiak31-Mar-06 4:40
mveDave Kreskowiak31-Mar-06 4:40 
QuestionDataset.HasChanges won't becomeTrue! Pin
MohammadAmiry30-Mar-06 12:59
MohammadAmiry30-Mar-06 12:59 
Questiontopmost Pin
SVb.net30-Mar-06 12:07
SVb.net30-Mar-06 12:07 
AnswerRe: topmost Pin
Steve Pullan30-Mar-06 12:59
Steve Pullan30-Mar-06 12:59 
AnswerRe: topmost Pin
Joshua Quick30-Mar-06 14:06
Joshua Quick30-Mar-06 14:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.