Solved

Moving  Forms  as they are. (intact)

Posted on 2004-08-15
14
178 Views
Last Modified: 2010-05-02
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
Comment
Question by:Jimmyx1000
  • 5
  • 4
  • 2
  • +2
14 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11807189
In Windows 2000, there is a checkbox captioned 'Show window properties while dragging', under the 'Effects' tab of the 'Display properties' dialogue.
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 250 total points
ID: 11807250
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
 
LVL 8

Expert Comment

by:SNilsson
ID: 11807260
You can set a the registry setting from with in VB:

HKEY_CURRENT_USER\Control Panel\Desktop\DragFullWindows

Set this value to 1
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 11807264

..And just so you know it, a reboot is needed for it to take effect (possibly only a log off/log on).
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11807428
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11807447
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
 

Author Comment

by:Jimmyx1000
ID: 11816351
GrahamSkan,  i cant get your code to work

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

Much appreciated expert.



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11817056
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
 

Author Comment

by:Jimmyx1000
ID: 11817217
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
 
LVL 7

Accepted Solution

by:
Burbble earned 250 total points
ID: 11817372
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
 
LVL 7

Expert Comment

by:Burbble
ID: 11817380
>> 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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11818032
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
 
LVL 7

Expert Comment

by:Burbble
ID: 11823793
>> 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
 
LVL 7

Expert Comment

by:Burbble
ID: 11909226
Thanks for the points, glad I could help :-)

-Burbble
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now