Solved

Moving  Forms  as they are. (intact)

Posted on 2004-08-15
14
179 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

777 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