I have a small player built on a frame. At form_load, I set the form width/height equal to the size of the design (two fixed size images on top of each other.
The form has no border, no control (dock, min, max, exit).
When running, the user wants to move the frame on the screen by dragging the frame.
How can this be achieved? (I can drag thing WITHIN the frame, but NOT the FRAME!)
Help!

You meant to say you have a borderless form and on top you have a frame whose size = size of form...

so ultimately the user interacts only with the frame... check the drag operation/ Function etc of the Frame instead of Form.

Or have i misunderstood?!

My (silly) mistake:
It is a FORM, of course.
The form has no border, no min/max/exit, and is 300 x 200 pixels only.
The form is entirely covered with two IMAGEs (one shows a screen, the other a control panle).
At start, it opens centered on the screen.
I can move the IMAGE within the FORM, but not the FORM itself (i.e. to move it on the top left corner of my screen).
How can I do it?

You just want to move it to the top left corner? If yes, Do this in your Form_Load():

me.Left=0
me.Top=0

If you want to allow people to DRAG the form then post again.

Did it!
main form = frmMain (form)
Top image = PlayerTop (image)
Bottom image = PlayerSlim (image)
PlayerTop + PlayerSlim = total size of frmMain (no borders)
FrmMove = global boolean
DragX, DragY: globals

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    FrmMove = True
    DragX = X
    DragY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim nx, ny
    If FrmMove Then
        nx = frmMain.Left + X - DragX
        ny = frmMain.Top + Y - DragY
        frmMain.Left = nx
        frmMain.Top = ny
    End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim nx, ny
    nx = frmMain.Left + X - DragX
    ny = frmMain.Top + Y - DragY
    frmMain.Left = nx
    frmMain.Top = ny
    FrmMove = False
End Sub
Private Sub PlayerSlim_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_MouseDown Button, Shift, X, Y
End Sub
Private Sub PlayerSlim_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_MouseMove Button, Shift, X, Y
End Sub
Private Sub PlayerSlim_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_MouseUp Button, Shift, X, Y
End Sub
Private Sub PlayerTop_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_MouseDown Button, Shift, X, Y
End Sub
Private Sub PlayerTop_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_MouseMove Button, Shift, X, Y
End Sub
Private Sub PlayerTop_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form_MouseUp Button, Shift, X, Y
End Sub

Click and drag on any of the two images moves the form.
Thanks anyway.

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    Me.Cursor = Cursors.NoMove2D
    mouseTop = Me.Top - (Cursor.Position.Y)
    mouseLeft = Me.Left - (Cursor.Position.X)
    moveFrm = True

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    If moveFrm = True Then
        posTop = (Cursor.Position.Y)
        posLeft = (Cursor.Position.X)
        Me.Top = mouseTop + posTop
        Me.Left = mouseLeft + posLeft
    End If

End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    Me.Cursor = Cursors.Default
    moveFrm = False

End Sub

that's the easiest way i know of....

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I working on a framless application and found this page with google. I couldn't get the above code working so I wrote my own routine. It's smaller and can use any controll with MouseMove to move the form. Here it is for anybody else who finds this.

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static xx As Integer, yy As Integer
Select Case Button
Case 0
    xx = X
    yy = Y
Case 1
    Me.Left = Me.Left + (X - xx)
    Me.Top = Me.Top + (Y - yy)
End Select
End Sub

Or just simply add this

  • Dim xm as integer
  • Dim ym as integer

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
* if button = 1 then
* me.left = me.left + X - xm
* me.top = me.top + Y - Ym
* End if
* End sub

  • Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  • Xm = X
  • ym = Y
  • End sub
This question has already been answered. Start a new discussion instead.