473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Drag form by dragging a label

Ali Rizwan
925 512MB
Hi all,
I want to drag my form which has no title bar but has a label. I want to drag my form by the help of that label.
Thanx
Oct 6 '07 #1
1 1302
Killer42
8,435 Expert 8TB
Does it have to be the label that is used to drag the form? Here's an example (VB6) that lets you simply grab the form (anywhere on the form) and drag it.

This version won't work if you grab any controls (such as a label), but you can change it if necessary.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3. Private Dragging As Boolean
  4. Private DragX As Single, DragY As Single
  5.  
  6.  
  7. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  8.   Dragging = True
  9.   DragX = X: DragY = Y
  10. End Sub
  11.  
  12. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  13.   Dim OffsetX As Single, OffsetY As Single
  14.   Static Busy As Boolean
  15.   If Not Busy Then
  16.     Busy = True
  17.     If Dragging Then
  18.       OffsetX = X - DragX
  19.       OffsetY = Y - DragY
  20.  
  21.       With Me
  22.         .Move .Left + OffsetX, Top + OffsetY
  23.       End With
  24.       DoEvents
  25.     End If
  26.     Busy = False
  27.   End If
  28. End Sub
  29.  
  30. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  31.   Dragging = False
  32. End Sub
Oct 7 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
1
by: Kevin L | last post by:
I have a Panel control that I currently allow the user to drag and reposition on a form at runtime. This Panel control contains a Label control. I would like to allow the user to drag the PANEL...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.