Banner

Trascinare con il mouse una Form senza bordi

Per poter trascinare sullo schermo una form priva di bordo, (proprietà FormBorderStyle=None) ho usato queste poche righe di codice:

Public Class Form1

    Dim mousePremuto As Boolean = False
    Dim diff As Point

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles Me.MouseDown

        mousePremuto = True
        diff = New Point(-e.X, -e.Y)

    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles Me.MouseMove

        If e.Button = MouseButtons.Left AndAlso mousePremuto = True Then
            Dim mouse_pos As Point = Control.MousePosition
            mouse_pos.Offset(diff.X, diff.Y)
            Me.Location = mouse_pos
        End If

    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles Me.MouseUp

        mousePremuto = False

    End Sub

End Class
Siti Ufficiali Editor Free Guide Online Utility
Microsoft Visual Studio MSDN InnoSetup
Apple XCode Documentazione .Net Cyber Installer
Oracle NetBeans Apple Developer NSIS
Debian Eclipse W3C Diagram Online
Distrowatch Bluefish W3C Validator Junior Icon Editor
Brackets W3Schools Edit Cursors Online
TextWrangler

Sito realizzato da Fiaschi Francesco - Aggiornamento Dicembre 2018

W3C - XHTML 1.1 Validated