|
-
May 25th, 2005, 06:13 PM
#1
Thread Starter
Frenzied Member
Moving a command
Hi to all:
I need to let the user move a command1 in a form!
How can I do This?
Thanks
-
May 25th, 2005, 06:26 PM
#2
Re: Moving a command
 Originally Posted by sacramento
Hi to all:
I need to let the user move a command1 in a form!
How can I do This?
Thanks
Try This Post
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
May 25th, 2005, 06:26 PM
#3
Re: Moving a command
Try something like this:
VB Code:
Dim intxx As Integer
Dim intyy As Integer
Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
intxx = X
intyy = Y
cmdButton.MousePointer = vbSizeAll
End If
End Sub
Private Sub cmdButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
cmdButton.Left = (cmdButton.Left - intxx) + X
cmdButton.Top = (cmdButton.Top - intyy) + Y
End If
End Sub
Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdButton.MousePointer = vbDefault
End Sub
Cheers,
RyanJ
-
May 25th, 2005, 06:37 PM
#4
Thread Starter
Frenzied Member
Re: Moving a command
Thanks for the thread:
This is the code:
VB Code:
Option Explicit
Private mbDragging As Boolean
Private nX As Single, nY As Single
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Text1.Move X - nX, Y - nY
mbDragging = False
End Sub
Private Sub Text1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
If Not mbDragging Then
nX = X
nY = Y
mbDragging = True
End If
End Sub
In fact works very well,but I want fixed the object moved to the position I had left him.
Any suggestions?
Thanks
-
May 25th, 2005, 06:46 PM
#5
Fanatic Member
Re: Moving a command
For something different, try this:
Create a new project, add a command button on to it and add this code to the form:
VB Code:
Option Explicit
Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Command1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End Sub
Does this do what you want?
-
May 25th, 2005, 06:50 PM
#6
Thread Starter
Frenzied Member
Re: Moving a command
Hi Blade:
Yes that's what I want and work very well,but I stay with the same problem.The command1 don't fix the position where I had move it!
Do you have any suggestion to do this?
Thanks
-
May 25th, 2005, 06:55 PM
#7
Fanatic Member
Re: Moving a command
Not sure I understand you.
If I move the command button with the code I posted, it stays wherever I put it? Are you calling some other code that resets it position?
-
May 25th, 2005, 06:59 PM
#8
Thread Starter
Frenzied Member
Re: Moving a command
yes that correct the object stays wherever I put it,but if you leave the form and enter again the object is in the original position you had put it in the form!
Do you mean what I say?
Thanks
-
May 25th, 2005, 07:03 PM
#9
Re: Moving a command
 Originally Posted by sacramento
yes that correct the object stays wherever I put it,but if you leave the form and enter again the object is in the original position you had put it in the form!
Do you mean what I say?
Thanks
Oh, you want to make it there perminamt perminant....
The only way I can think to do this is to store the information in a file and then use that to load the control in the correct place when the form is loaded.
Cheers,
RyanJ
-
May 25th, 2005, 07:06 PM
#10
Fanatic Member
Re: Moving a command
right. Yep, as Ryan say, you'll need to store it's location in a file (or registry/database) and then get this info everytime you load the form up.
-
May 25th, 2005, 07:08 PM
#11
Thread Starter
Frenzied Member
Re: Moving a command
ok I see...something like this?
data1.recordset![position]=command1.top
data1.recordset![position1]=command1.left
-
May 25th, 2005, 07:09 PM
#12
Re: Moving a command
 Originally Posted by sacramento
ok I see...something like this?
data1.recordset![position]=command1.top
data1.recordset![position1]=command1.left
Exactly 
Maybe the registry would be better in this case because is is only two values...?
RyanJ
-
May 25th, 2005, 07:11 PM
#13
Re: Moving a command
try this
VB Code:
Option Explicit
Dim intxx As Integer
Dim intyy As Integer
Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
intxx = X
intyy = Y
Cmdbutton.MousePointer = vbSizeAll
End If
End Sub
Private Sub cmdButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Cmdbutton.Left = (Cmdbutton.Left - intxx) + X
Cmdbutton.Top = (Cmdbutton.Top - intyy) + Y
End If
End Sub
Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Cmdbutton.MousePointer = vbDefault
End Sub
Private Sub Form_Load()
If len(Cmdbutton.Left = GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 then
Cmdbutton.Left = GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)
Cmdbutton.Top = GetSetting(App.EXEName, "settings", "Y", Cmdbutton.Top)
end if
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveSetting App.EXEName, "settings", "X", Cmdbutton.Left
SaveSetting App.EXEName, "settings", "Y", Cmdbutton.Top
End Sub
-
May 25th, 2005, 07:26 PM
#14
Thread Starter
Frenzied Member
Re: Moving a command
I have problems with this line...I don't now why...the object is there!!!
run time error '424'
object required
Code:
If len(Cmdbutton.Left = GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 then
-
May 25th, 2005, 07:34 PM
#15
Re: Moving a command
Try changing it too:
VB Code:
If Len(GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 Then
Cheers,
RyanJ
-
May 25th, 2005, 07:39 PM
#16
Thread Starter
Frenzied Member
Re: Moving a command
something strange...now the error is
variable not define
Code:
If Len(GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 Then
-
May 25th, 2005, 07:39 PM
#17
Re: Moving a command
woops my bad..shows what copying and pasting gets you ;?
-
May 25th, 2005, 07:40 PM
#18
Re: Moving a command
you have a command button named cmdbutton...right?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|