Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

no bordered forms

is there a way to drag forms with no border?
0
greansleve
Asked:
greansleve
  • 3
  • 2
  • 2
  • +2
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

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.

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