473,382 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to move the CommandButton control using mouse from one position to other?

Hi All,

How to move the CommandButton control using mouse from one position to
other?
Is it possible using Drag, Drop events or I have to write my own code for
that?

I have set the "AllowDrop" property to true. But when I try to drag the
Button it doesn't move.
Any help will be appreciated.

Thanks and Regards
Sakharam Phapale
Nov 21 '05 #1
6 7872
This should do it

<<<<<<code>>>>>>

Private dragging As Boolean
Private beginX, beginY As Integer

Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown

dragging = True
beginX = e.X
beginY = e.Y

End Sub

Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
If dragging = True Then
Button2.Location = New Point(Button2.Location.X + e.X -
beginX,Button2.Location.Y + e.Y - beginY)
Me.Refresh()
End If
End Sub

Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp

dragging = False

End Sub
<<<<<<code>>>>>>>
hth Peter

"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi All,

How to move the CommandButton control using mouse from one position to
other?
Is it possible using Drag, Drop events or I have to write my own code for
that?

I have set the "AllowDrop" property to true. But when I try to drag the
Button it doesn't move.
Any help will be appreciated.

Thanks and Regards
Sakharam Phapale

Nov 21 '05 #2
Hi Peter,

Thanks for your reply.

I want to use Drag and Drop events.
Any idea?

Thanks and regards
Sakharam Phapale
"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
This should do it

<<<<<<code>>>>>>

Private dragging As Boolean
Private beginX, beginY As Integer

Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown

dragging = True
beginX = e.X
beginY = e.Y

End Sub

Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
If dragging = True Then
Button2.Location = New Point(Button2.Location.X + e.X -
beginX,Button2.Location.Y + e.Y - beginY)
Me.Refresh()
End If
End Sub

Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp

dragging = False

End Sub
<<<<<<code>>>>>>>
hth Peter

"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi All,

How to move the CommandButton control using mouse from one position to
other?
Is it possible using Drag, Drop events or I have to write my own code for that?

I have set the "AllowDrop" property to true. But when I try to drag the
Button it doesn't move.
Any help will be appreciated.

Thanks and Regards
Sakharam Phapale


Nov 21 '05 #3
Sakharam,

I want to use Drag and Drop events.
Any idea?


Why, does the sample from Peter not work?

Cor
Nov 21 '05 #4
Hi Sakharam,

Drag drop is used for dragging and dropping data (for example from one
listbox to another) it doesn't move a control, you have to write your own
code to move a control like for example the code I posted.

Greetz Peter

"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:uU**************@TK2MSFTNGP15.phx.gbl...
Hi Peter,

Thanks for your reply.

I want to use Drag and Drop events.
Any idea?

Thanks and regards
Sakharam Phapale
"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
This should do it

<<<<<<code>>>>>>

Private dragging As Boolean
Private beginX, beginY As Integer

Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown

dragging = True
beginX = e.X
beginY = e.Y

End Sub

Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
If dragging = True Then
Button2.Location = New Point(Button2.Location.X + e.X -
beginX,Button2.Location.Y + e.Y - beginY)
Me.Refresh()
End If
End Sub

Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp

dragging = False

End Sub
<<<<<<code>>>>>>>
hth Peter

"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi All,

How to move the CommandButton control using mouse from one position to
other?
Is it possible using Drag, Drop events or I have to write my own code for that?

I have set the "AllowDrop" property to true. But when I try to drag the Button it doesn't move.
Any help will be appreciated.

Thanks and Regards
Sakharam Phapale



Nov 21 '05 #5
He wants to use the DoDragDrop methods of the the Controls he wants to move.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Sakharam,

I want to use Drag and Drop events.
Any idea?


Why, does the sample from Peter not work?

Cor

Nov 21 '05 #6
Terry,

I know, however the answer from Peter is in my opinion very good and very
efficient, so why botter to do it in a more difficult way?

I once saw in this newsgroup somebody fighting to do it with the drag and
drop while the method from Peter is so easy. (I would have given an answer
as that when Peter had not done that)

I even do not know if it is possible with drag and drop.

Cor
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: William Bub | last post by:
I am using VB 6.0 Working Model (the one with no help files). I have a form. On a portion of the form I have a Picture Box. On the PicBox I want to draw something to follow the mouse. I can detect...
2
by: Roger | last post by:
I'm trying to build a controls editor, that given a control (textbox) somewhere on a form, it can be moved using the mouse to drag-drop I have a simple form with a square text box (1" x 1") and...
1
by: gmtongar | last post by:
Hi, I've made a custom scrollbar which consists of three buttons and a panel. My problem is: How do I move it like a scrollbar slider? I've tried DoDragDrop, but it does not appear to be the same,...
3
by: Tomomichi Amano | last post by:
This is a addition to the question I did earlier. What event should I use to make some think happen everytime the mouse moves (anywhere on the screen)?
0
by: Rob R. Ainscough | last post by:
Has anyone else had this problem? I'm in GridLayout, if I add a new Label control and try to move/position it to the bottom page using the arrow keys it just stops at the bottom and doesn't let...
6
by: Rob | last post by:
This is a curious problem. It seems like it should be quite easy. Of course a timer is used to determine when form should be closed, but how do you consistently reset the timer when the mouse is...
2
by: mmdst23 | last post by:
I'm working on a video player app, and I want to implement a trackbar that behaves like the one in Media Player, that is the cursor position moves to where the user clicked instead of moving in...
0
by: hmm | last post by:
Hi all I have two problems: Problem #1: I'm using a .NET Form with the property 'FormBorderStyle' set to 'None'. The idea is to completely cover the area of that Form with a UserControl. In...
7
by: Joe-Paul Robb, Jr. | last post by:
Hello: I am building a program in Visual Basic 6.0. (Op Sys: Windows XP 2002 Service Pack 2) I placed an AOD Data Control on a form...and a data Grid. I bound the data grid to the data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.