no bordered forms

is there a way to drag forms with no border?
greansleveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
I don't think so, becuase the 'handle' of the form is the Title Bar, and that requires a Border.

AW
0
greansleveAuthor Commented:
aint there some sort of code that will let you drag the form?
0
bob_onlineCommented:
On Form_MouseDown, store the X and Y coordinates from the mousedown event in module level variables StartX and StartY.

On Form_MouseMove

If Button = vbLeftButton Then
   Me.Left = Me.Left - (StartX - X)
   Me.Top = Me.Top - (StartY - Y)
End If
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

bob_onlineCommented:
Sorry, prior comment had "-" where I should have had "+"

On Form_MouseDown, store the X and Y coordinates from the mousedown event in module level variables StartX and StartY.

On Form_MouseMove

If Button = vbLeftButton Then
  Me.Left = Me.Left + (StartX - X)
  Me.Top = Me.Top + (StartY - Y)
End If
0
greansleveAuthor Commented:
sorry *n00bie to this sorta stuff*

I dont understand 'store the X and Y coordinates from the mousedown event in module level variables StartX and StartY'

could you explain please :)
0
fluglashCommented:
BorderStyle property = None  in design time
0
tmorellCommented:
Here's a solution using the API. Click anywhere in the form and move the mouse to move the window

Create new project with one form.  Set BorderStyle property of form to 0-None.

Add this code to the form:

Option Explicit
Dim tpoint As POINTAPI
Dim temp  As POINTAPI
Dim dpoint As POINTAPI

Dim fbox As RECT
Dim tbox As RECT
Dim oldbox As RECT

Dim TwipsPerPixelX
Dim TwipsPerPixelY

Private Sub Form_Load()
   Dim frameHeight As Long
   Dim frameWidth As Long
   
  'compute the width of the left and right dialog frame
   frameHeight = GetSystemMetrics(SM_CYDLGFRAME) * 2
   
  'compute the width of the top and bottom dialog frame
   frameWidth = GetSystemMetrics(SM_CXDLGFRAME) * 2
   

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

    BeginFRDrag x, y
     
End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

    If Button = 1 Then DoFRDrag x, y
   
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
   
    EndFRDrag x, y

End Sub


Private Sub BeginFRDrag(x As Single, y As Single)

    Dim tDc As Long
    Dim sDc As Long
    Dim d As Long
   
   'convert points to POINTAPI struct
    dpoint.x = x
    dpoint.y = y
   
   'get screen area of window
    GetWindowRect Me.hwnd, fbox
   'screen RECT of toolbar
    TwipsPerPixelX = Screen.TwipsPerPixelX
    TwipsPerPixelY = Screen.TwipsPerPixelY
   
   'get point of MouseDown in screen coordinates
    temp = dpoint
    ClientToScreen Me.hwnd, temp

    sDc = GetDC(ByVal 0)
    DrawFocusRect sDc, tbox
    d = ReleaseDC(0, sDc)
    oldbox = tbox

End Sub


Private Sub DoFRDrag(x As Single, y As Single)

    Dim tDc As Long
    Dim sDc As Long
    Dim d As Long
   
    tpoint.x = x
    tpoint.y = y

    ClientToScreen Me.hwnd, tpoint

    tbox.Left = (fbox.Left + tpoint.x / TwipsPerPixelX) - temp.x / TwipsPerPixelX
    tbox.Top = (fbox.Top + tpoint.y / TwipsPerPixelY) - temp.y / TwipsPerPixelY
    tbox.Right = (fbox.Right + tpoint.x / TwipsPerPixelX) - temp.x / TwipsPerPixelX
    tbox.Bottom = (fbox.Bottom + tpoint.y / TwipsPerPixelY) - temp.y / TwipsPerPixelY

    sDc = GetDC(ByVal 0)
    DrawFocusRect sDc, oldbox
    DrawFocusRect sDc, tbox
    d = ReleaseDC(0, sDc)
    oldbox = tbox

End Sub


Private Sub EndFRDrag(x As Single, y As Single)

    Dim tDc As Long
    Dim sDc As Long
    Dim d As Long
   
    Dim newleft As Single
    Dim newtop As Single

    sDc = GetDC(ByVal 0)
    DrawFocusRect sDc, oldbox
    d = ReleaseDC(0, sDc)

    newleft = x + fbox.Left * TwipsPerPixelX - dpoint.x
    newtop = y + fbox.Top * TwipsPerPixelY - dpoint.y
   
    Me.Move newleft, newtop

End Sub



Create a BAS module and place this code in it:

Public Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Public Type POINTAPI
   x As Long
   y As Long
End Type

Public Const COLOR_ACTIVECAPTION = 2
Public Const SM_CXDLGFRAME = 7
Public Const SM_CYDLGFRAME = 8

Public Declare Function GetWindowRect Lib "user32" _
    (ByVal hwnd As Long, lpRect As RECT) As Long
   
Public Declare Function GetSysColor Lib "user32" _
    (ByVal nIndex As Long) As Long
   
Public Declare Function GetSystemMetrics Lib "user32" _
    (ByVal nIndex As Long) As Long

Public Declare Function DrawFocusRect Lib "user32" _
    (ByVal hdc As Long, lpRect As RECT) As Long
   
Public Declare Function ClientToScreen Lib "user32" _
    (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
   
Public Declare Function GetDC Lib "user32" _
    (ByVal hwnd As Long) As Long
   
Public Declare Function ReleaseDC Lib "user32" _
    (ByVal hwnd As Long, ByVal hdc As Long) As Long

Modfied some code I found on VBNet to do this.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fluglashCommented:
tmorell:
perhaps it`s better to use assembler????
0
tmorellCommented:
fluglash:
Don't think so.
Looks compicated but works very well and very fast, and, once you have it, re-use it!
0
greansleveAuthor Commented:
long code, but all the same it works. cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.