• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Moving Forms as they are. (intact)

How Can i move my form as it is ?

For example when i move a  form with the  mouse up down left right
the form disappears and you get a square box outline , when you let the mouse go
the form appears  again. this is standard when moving any form with windows.

So basically i would like to move my form as it is without it disappearing and
then appearing when you let the mouse button go.

How can i code this ?

thankyou Experts


 

0
Jimmyx1000
Asked:
Jimmyx1000
  • 5
  • 4
  • 2
  • +2
2 Solutions
 
GrahamSkanRetiredCommented:
In Windows 2000, there is a checkbox captioned 'Show window properties while dragging', under the 'Effects' tab of the 'Display properties' dialogue.
0
 
GrahamSkanRetiredCommented:
You can get something like it with this code.

Option Explicit
Dim gX As Single
Dim gY As Single
Dim Oldleft  As Single
Dim OldTop As Single
Dim gDragging As Boolean

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
OldTop = Me.Top
Oldleft = Me.Left
gX = X
gY = Y
gDragging = True
End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If gDragging Then
Me.Move Oldleft + X - gX, OldTop + Y - gY
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
gDragging = False
End Sub


0
 
SNilssonCommented:
You can set a the registry setting from with in VB:

HKEY_CURRENT_USER\Control Panel\Desktop\DragFullWindows

Set this value to 1
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
SNilssonCommented:

..And just so you know it, a reboot is needed for it to take effect (possibly only a log off/log on).
0
 
JR2003Commented:
In XP in the Display properties dialog it's under the Appearance tab. This tab contains a button called "Effects..." and it can be found in there.
0
 
GrahamSkanRetiredCommented:
Jimmyx1000
You have 13 open questions (including this one). I suggest that you have a look and see if any of them can be closed.
Cheers, Graham
0
 
Jimmyx1000Author Commented:
GrahamSkan,  i cant get your code to work

can you accomadate your code to work with a standard  vb form

Much appreciated expert.



0
 
GrahamSkanRetiredCommented:
Hi Jimmyx1000
This code works in Windows 2000 with VB6. The effect is rather jittery and not to be recommended over the method built in to the operating system that can be enabled according to my first comment (by checking: 'Show window properties while dragging').
What versions of windows and of  VB are you using?
Graham
0
 
Jimmyx1000Author Commented:
GrahamSkan  

Im using windows 2000 and vb6

Id like to make this drag feature OS independent.

How can i code this with a standard basic form

thanks GrahamSkan  

0
 
BurbbleCommented:
Here's some code I wrote based on the same principle of GrahamSkan's...

Add a tmrDragging to a Form, with an interval of 1
-----
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Dim CurrentPosition As POINTAPI
Dim OldPosition As POINTAPI
Dim OldLeft As Integer
Dim OldTop As Integer

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    GetCursorPos OldPosition
    OldLeft = Me.Left / Screen.TwipsPerPixelX
    OldTop = Me.Top / Screen.TwipsPerPixelY
    tmrDragging.Enabled = True
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    tmrDragging.Enabled = False
End Sub

Private Sub tmrDragging_Timer()
    GetCursorPos CurrentPosition
    Me.Move Screen.TwipsPerPixelX * (OldLeft + CurrentPosition.X - OldPosition.X), Screen.TwipsPerPixelY * (OldTop + CurrentPosition.Y - OldPosition.Y)
End Sub
-----

-Burbble
0
 
BurbbleCommented:
>> Add a tmrDragging to a Form, with an interval of 1

Should have read:

Add a Timer with an interval of 1, named tmrDragging, to a Form.

-Burbble
0
 
GrahamSkanRetiredCommented:
Burbble's code improves the performance. You might like to add this bit, to ensure that the timer is set up.

Sub Form_Load()
    tmrDragging.Enabled = False
    tmrDragging.Interval = 20
End Sub

Neither set of code is OS version-dependent. However, the drag only works if you click on the form body - not the title area.
0
 
BurbbleCommented:
>> tmrDragging.Enabled = False

Whoops, forgot to mention that, thanks :)

>> However, the drag only works if you click on the form body - not the title area.

This is true...

-Burbble
0
 
BurbbleCommented:
Thanks for the points, glad I could help :-)

-Burbble
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now