Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
' Code that extends the form with dragging abilities
#Region " Partial Class - Dragging "
Partial Public Class DynForm
#Region "Declarations"
Delegate Sub MouseLocationChangedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Delegate Sub DragTypesChangedHandler(ByVal sender As Object, ByVal e As System.EventArgs)
''' <summary>Occurs when the mouse location is changed during a drag when the drag functionallity is enabled</summary>
Public Event MouseLocationChanged As MouseLocationChangedHandler
''' <summary>Occurs when a change to the collection of drag types is made</summary>
Public Event DragTypesChanged As DragTypesChangedHandler
Private m_allowedTypes As New List(Of Type)
Private m_mouseLoc As New Point
Private m_enableDrag As Boolean
#End Region
#Region "Private"
Private Sub addDefaultDragTypes()
Me.DragTypes.AddRange(New Type() {Me.GetType, GetType(Label), GetType(ListBox), GetType(Button), GetType(PictureBox), GetType(ProgressBar), GetType(TextBox), GetType(RichTextBox), GetType(MenuStrip), GetType(StatusStrip), GetType(ComboBox), GetType(RadioButton), GetType(CheckBox)})
End Sub
Private Sub MyBase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
makeFormDragable(Me)
End Sub
Private Sub makeFormDragable(ByVal form As Form)
addDragHandlers(form)
For Each ctrl As Control In form.Controls
addDragHandlers(ctrl)
Next
End Sub
Private Sub addDragHandlers(ByVal ctrl As Control)
With ctrl
For Each aType As Type In Me.DragTypes
If aType Is ctrl.GetType Then
AddHandler .MouseDown, AddressOf Ctrl_MouseDown
AddHandler .MouseMove, AddressOf Ctrl_MouseMove
Exit For
End If
Next
End With
End Sub
Private Sub Ctrl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If Me.Drag Then Me.MouseLocation = New Point(MousePosition.X - Me.Location.X, MousePosition.Y - Me.Location.Y)
End Sub
Private Sub Ctrl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Left And Me.Drag Then
Me.Location = New Point(MousePosition.X - MouseLocation.X, MousePosition.Y - MouseLocation.Y)
End If
End Sub
#End Region
#Region "Properties"
''' <summary>Gets or sets the current mouse drag location</summary>
<Browsable(True), Category("Drag"), Description("Gets or sets the current mouse drag location")> _
Public Property MouseLocation() As Point
Get
Return m_mouseLoc
End Get
Set(ByVal value As Point)
If value <> m_mouseLoc Then m_mouseLoc = value : RaiseEvent MouseLocationChanged(Me, New System.EventArgs())
End Set
End Property
''' <summary>Gets or sets the drag types collection. The user will be able to drag the form when dragging an object of a type contained by this collection</summary>
<Browsable(True), Category("Drag"), Description("Gets or sets the drag types collection. The user will be able to drag the form when dragging an object of a type contained by this collection")> _
Public Property DragTypes() As List(Of Type)
Get
Return m_allowedTypes
End Get
Set(ByVal value As List(Of Type))
If value IsNot m_allowedTypes Then m_allowedTypes = value : RaiseEvent DragTypesChanged(Me, New System.EventArgs)
End Set
End Property
''' <summary>Gets or sets wheter advanced drag should be enabled</summary>
<Browsable(True), Category("Drag"), Description("Gets or sets wheter advanced drag should be enabled")> _
Public Property Drag() As Boolean
Get
Return m_enableDrag
End Get
Set(ByVal value As Boolean)
m_enableDrag = value
End Set
End Property
#End Region
End Class
#End Region
Public Class Form1
Dim StartX, StartY As Integer
Dim Dragging As Boolean
Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
Dragging = True
StartX = e.X
StartY = e.Y
End Sub
Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If Dragging = True Then
Label1.Left = (Label1.Left + e.X) - StartX
Label1.Top = (Label1.Top + e.Y) - StartY
End If
End Sub
Private Sub Label1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
Dragging = False
End Sub
End Class
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.