Hi to all:
I need to let the user move a command1 in a form!
How can I do This?
Thanks
Printable View
Hi to all:
I need to let the user move a command1 in a form!
How can I do This?
Thanks
Quote:
Originally Posted by sacramento
Try This Post
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
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
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?
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
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?
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
Quote:
Originally Posted by sacramento
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
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.
ok I see...something like this?
data1.recordset![position]=command1.top
data1.recordset![position1]=command1.left
Exactly :)Quote:
Originally Posted by sacramento
Maybe the registry would be better in this case because is is only two values...?
RyanJ
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
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
Try changing it too:
VB Code:
If Len(GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 Then
Cheers,
RyanJ
something strange...now the error is
variable not define
Code:
If Len(GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 Then
woops my bad..shows what copying and pasting gets you ;?
you have a command button named cmdbutton...right?