?
Solved

no bordered forms

Posted on 2003-02-28
10
Medium Priority
?
200 Views
Last Modified: 2010-05-03
is there a way to drag forms with no border?
0
Comment
Question by:greansleve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 44

Expert Comment

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

AW
0
 

Author Comment

by:greansleve
ID: 8042897
aint there some sort of code that will let you drag the form?
0
 
LVL 5

Expert Comment

by:bob_online
ID: 8043024
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!

 
LVL 5

Expert Comment

by:bob_online
ID: 8043043
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
 

Author Comment

by:greansleve
ID: 8043049
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
 
LVL 7

Expert Comment

by:fluglash
ID: 8043156
BorderStyle property = None  in design time
0
 

Accepted Solution

by:
tmorell earned 150 total points
ID: 8043265
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
 
LVL 7

Expert Comment

by:fluglash
ID: 8043342
tmorell:
perhaps it`s better to use assembler????
0
 

Expert Comment

by:tmorell
ID: 8043386
fluglash:
Don't think so.
Looks compicated but works very well and very fast, and, once you have it, re-use it!
0
 

Author Comment

by:greansleve
ID: 8043713
long code, but all the same it works. cheers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 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