Advertisement
PiToLoKo

FormDragger Manager written in VB.Net, by Elektro (rev. 4)

Mar 14th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 22.02 KB | None | 0 0
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 15-March-2015
  4. ' ***********************************************************************
  5. ' <copyright file="FormDragger.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Option Statements "
  11.  
  12. Option Explicit On
  13. Option Strict On
  14. Option Infer Off
  15.  
  16. #End Region
  17.  
  18. #Region " Usage Examples "
  19.  
  20. 'Public Class Form1
  21.  
  22. '    ''' <summary>
  23. '    ''' The <see cref="FormDragger"/> instance that manages the form(s) dragging.
  24. '    ''' </summary>
  25. '    Private formDragger As FormDragger = FormDragger.Empty
  26.  
  27. '    Private Sub Test() Handles MyBase.Shown
  28. '        Me.InitializeDrag()
  29. '    End Sub
  30.  
  31. '    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
  32. '    Handles Button1.Click
  33.  
  34. '        Me.AlternateDragEnabled(Me)
  35.  
  36. '    End Sub
  37.  
  38. '    Private Sub InitializeDrag()
  39.  
  40. '        ' 1st way, using the single-Form constructor:
  41. '        Me.formDragger = New FormDragger(Me, enabled:=True, cursor:=Cursors.SizeAll)
  42.  
  43. '        ' 2nd way, using the multiple-Forms constructor:
  44. '        ' Me.formDragger = New FormDragger({Me, Form2, form3})
  45.  
  46. '        ' 3rd way, using the default constructor then adding a Form into the collection:
  47. '        ' Me.formDragger = New FormDragger
  48. '        ' Me.formDragger.AddForm(Me, enabled:=True, cursor:=Cursors.SizeAll)
  49.  
  50. '    End Sub
  51.  
  52. '    ''' <summary>
  53. '    ''' Alternates the dragging of the specified form.
  54. '    ''' </summary>
  55. '    ''' <param name="form">The form.</param>
  56. '    Private Sub AlternateDragEnabled(ByVal form As Form)
  57.  
  58. '        Dim formInfo As FormDragger.FormDragInfo = Me.formDragger.FindFormDragInfo(form)
  59. '        formInfo.Enabled = Not formInfo.Enabled
  60.  
  61. '    End Sub
  62.  
  63. 'End Class
  64.  
  65. #End Region
  66.  
  67. #Region " Imports "
  68.  
  69. Imports System.ComponentModel
  70.  
  71. #End Region
  72.  
  73. #Region " Form Dragger "
  74.  
  75. ''' <summary>
  76. ''' Enable or disable drag at runtime on a <see cref="Form"/>.
  77. ''' </summary>
  78. Public NotInheritable Class FormDragger : Implements IDisposable
  79.  
  80. #Region " Properties "
  81.  
  82.     ''' <summary>
  83.     ''' Gets an <see cref="IEnumerable(Of Form)"/> collection that contains the Forms capables to perform draggable operations.
  84.     ''' </summary>
  85.     ''' <value>The <see cref="IEnumerable(Of Form)"/>.</value>
  86.     <EditorBrowsable(EditorBrowsableState.Always)>
  87.     Public ReadOnly Property Forms As IEnumerable(Of FormDragInfo)
  88.         Get
  89.             Return Me.forms1
  90.         End Get
  91.     End Property
  92.     ''' <summary>
  93.     ''' An <see cref="IEnumerable(Of Form)"/> collection that contains the Forms capables to perform draggable operations.
  94.     ''' </summary>
  95.     Private forms1 As IEnumerable(Of FormDragInfo) = {}
  96.  
  97.     ''' <summary>
  98.     ''' Represents a <see cref="FormDragger"/> instance that is <c>Nothing</c>.
  99.     ''' </summary>
  100.     ''' <value><c>Nothing</c></value>
  101.     <EditorBrowsable(EditorBrowsableState.Always)>
  102.     Public Shared ReadOnly Property Empty As FormDragger
  103.         Get
  104.             Return Nothing
  105.         End Get
  106.     End Property
  107.  
  108. #End Region
  109.  
  110. #Region " Types "
  111.  
  112.     ''' <summary>
  113.     ''' Defines the draggable info of a <see cref="Form"/>.
  114.     ''' </summary>
  115.     <Serializable>
  116.     Public NotInheritable Class FormDragInfo
  117.  
  118. #Region " Properties "
  119.  
  120.         ''' <summary>
  121.         ''' Gets the associated <see cref="Form"/> used to perform draggable operations.
  122.         ''' </summary>
  123.         ''' <value>The associated <see cref="Form"/>.</value>
  124.         <EditorBrowsable(EditorBrowsableState.Always)>
  125.         Public ReadOnly Property Form As Form
  126.             Get
  127.                 Return form1
  128.             End Get
  129.         End Property
  130.         ''' <summary>
  131.         ''' The associated <see cref="Form"/>
  132.         ''' </summary>
  133.         <NonSerialized>
  134.         Private ReadOnly form1 As Form
  135.  
  136.         ''' <summary>
  137.         ''' Gets the name of the associated <see cref="Form"/>.
  138.         ''' </summary>
  139.         ''' <value>The Form.</value>
  140.         <EditorBrowsable(EditorBrowsableState.Always)>
  141.         Public ReadOnly Property Name As String
  142.             Get
  143.                 If Me.Form IsNot Nothing Then
  144.                     Return Form.Name
  145.                 Else
  146.                     Return String.Empty
  147.                 End If
  148.             End Get
  149.         End Property
  150.  
  151.         ''' <summary>
  152.         ''' Gets or sets a value indicating whether drag is enabled on the associated <see cref="Form"/>.
  153.         ''' </summary>
  154.         ''' <value><c>true</c> if drag is enabled; otherwise, <c>false</c>.</value>
  155.         <EditorBrowsable(EditorBrowsableState.Always)>
  156.         Public Property Enabled As Boolean
  157.  
  158.         ''' <summary>
  159.         ''' A <see cref="FormDragger"/> instance instance containing the draggable information of the associated <see cref="Form"/>.
  160.         ''' </summary>
  161.         ''' <value>The draggable information.</value>
  162.         <EditorBrowsable(EditorBrowsableState.Never)>
  163.         Public Property DragInfo As FormDragger = FormDragger.Empty
  164.  
  165.         ''' <summary>
  166.         ''' Gets or sets the <see cref="Cursor"/> used to drag the associated <see cref="Form"/>.
  167.         ''' </summary>
  168.         ''' <value>The <see cref="Cursor"/>.</value>
  169.         <EditorBrowsable(EditorBrowsableState.Always)>
  170.         Public Property Cursor As Cursor = Cursors.SizeAll
  171.  
  172.         ''' <summary>
  173.         ''' Gets or sets the old form's cursor to restore it after dragging.
  174.         ''' </summary>
  175.         ''' <value>The old form's cursor.</value>
  176.         <EditorBrowsable(EditorBrowsableState.Never)>
  177.         Public Property OldCursor As Cursor = Nothing
  178.  
  179.         ''' <summary>
  180.         ''' Gets or sets the initial mouse coordinates, normally <see cref="Form.MousePosition"/>.
  181.         ''' </summary>
  182.         ''' <value>The initial mouse coordinates.</value>
  183.         <EditorBrowsable(EditorBrowsableState.Never)>
  184.         Public Property InitialMouseCoords As Point = Point.Empty
  185.  
  186.         ''' <summary>
  187.         ''' Gets or sets the initial <see cref="Form"/> location, normally <see cref="Form.Location"/>.
  188.         ''' </summary>
  189.         ''' <value>The initial location.</value>
  190.         <EditorBrowsable(EditorBrowsableState.Never)>
  191.         Public Property InitialLocation As Point = Point.Empty
  192.  
  193. #End Region
  194.  
  195. #Region " Constructors "
  196.  
  197.         ''' <summary>
  198.         ''' Initializes a new instance of the <see cref="FormDragInfo"/> class.
  199.         ''' </summary>
  200.         ''' <param name="form">The form.</param>
  201.         Public Sub New(ByVal form As Form)
  202.             Me.form1 = form
  203.             Me.Cursor = form.Cursor
  204.         End Sub
  205.  
  206.         ''' <summary>
  207.         ''' Prevents a default instance of the <see cref="FormDragInfo"/> class from being created.
  208.         ''' </summary>
  209.         Private Sub New()
  210.         End Sub
  211.  
  212. #End Region
  213.  
  214. #Region " Hidden Methods "
  215.  
  216.         ''' <summary>
  217.         ''' Serves as a hash function for a particular type.
  218.         ''' </summary>
  219.         <EditorBrowsable(EditorBrowsableState.Never)>
  220.         Public Shadows Function GetHashCode() As Integer
  221.             Return MyBase.GetHashCode
  222.         End Function
  223.  
  224.         ''' <summary>
  225.         ''' Gets the System.Type of the current instance.
  226.         ''' </summary>
  227.         ''' <returns>The exact runtime type of the current instance.</returns>
  228.         <EditorBrowsable(EditorBrowsableState.Never)>
  229.         Public Shadows Function [GetType]() As Type
  230.             Return MyBase.GetType
  231.         End Function
  232.  
  233.         ''' <summary>
  234.         ''' Determines whether the specified System.Object instances are considered equal.
  235.         ''' </summary>
  236.         <EditorBrowsable(EditorBrowsableState.Never)>
  237.         Public Shadows Function Equals(ByVal obj As Object) As Boolean
  238.             Return MyBase.Equals(obj)
  239.         End Function
  240.  
  241.         ''' <summary>
  242.         ''' Determines whether the specified System.Object instances are the same instance.
  243.         ''' </summary>
  244.         <EditorBrowsable(EditorBrowsableState.Never)>
  245.         Private Shadows Sub ReferenceEquals()
  246.         End Sub
  247.  
  248.         ''' <summary>
  249.         ''' Returns a String that represents the current object.
  250.         ''' </summary>
  251.         <EditorBrowsable(EditorBrowsableState.Never)>
  252.         Public Shadows Function ToString() As String
  253.             Return MyBase.ToString
  254.         End Function
  255.  
  256. #End Region
  257.  
  258.     End Class
  259.  
  260. #End Region
  261.  
  262. #Region " Constructors "
  263.  
  264.     ''' <summary>
  265.     ''' Initializes a new instance of the <see cref="FormDragger"/> class.
  266.     ''' </summary>
  267.     Public Sub New()
  268.         Me.forms1={}
  269.     End Sub
  270.  
  271.     ''' <summary>
  272.     ''' Initializes a new instance of the <see cref="FormDragger"/> class.
  273.     ''' </summary>
  274.     ''' <param name="form">The <see cref="Form"/> used to perform draggable operations.</param>
  275.     ''' <param name="enabled">If set to <c>true</c>, enable dragging on the <see cref="Form"/>.</param>
  276.     ''' <param name="cursor">The <see cref="Cursor"/> used to drag the specified <see cref="Form"/>.</param>
  277.     Public Sub New(ByVal form As Form,
  278.                    Optional enabled As Boolean = False,
  279.                    Optional cursor As Cursor = Nothing)
  280.  
  281.         Me.forms1 =
  282.             {
  283.                 New FormDragInfo(form) With
  284.                          {
  285.                              .Enabled = enabled,
  286.                              .Cursor = cursor
  287.                          }
  288.             }
  289.  
  290.         Me.AssocHandlers(form)
  291.  
  292.     End Sub
  293.  
  294.     ''' <summary>
  295.     ''' Initializes a new instance of the <see cref="FormDragger"/> class.
  296.     ''' </summary>
  297.     ''' <param name="forms">The <see cref="Forms"/> used to perform draggable operations.</param>
  298.     Public Sub New(ByVal forms As IEnumerable(Of Form))
  299.  
  300.         Me.forms1 = (From form As Form In forms
  301.                      Select New FormDragInfo(form)).ToArray
  302.  
  303.         For Each form As Form In forms
  304.             Me.AssocHandlers(form)
  305.         Next form
  306.  
  307.     End Sub
  308.  
  309.     ''' <summary>
  310.     ''' Initializes a new instance of the <see cref="FormDragger"/> class.
  311.     ''' </summary>
  312.     ''' <param name="formInfo">
  313.     ''' The <see cref="FormDragInfo"/> instance
  314.     ''' that contains the <see cref="Form"/> reference and its draggable info.
  315.     ''' </param>
  316.     ''' <param name="mouseCoordinates">The current mouse coordinates.</param>
  317.     ''' <param name="location">The current location.</param>
  318.     Private Sub New(ByVal formInfo As FormDragInfo,
  319.                     ByVal mouseCoordinates As Point,
  320.                     ByVal location As Point)
  321.  
  322.         formInfo.InitialMouseCoords = mouseCoordinates
  323.         formInfo.InitialLocation = location
  324.  
  325.     End Sub
  326.  
  327. #End Region
  328.  
  329. #Region " Public Methods "
  330.  
  331.     ''' <summary>
  332.     ''' Adds the specified <see cref="Form"/> into the draggable <see cref="Forms"/> collection.
  333.     ''' </summary>
  334.     ''' <param name="form">The <see cref="Form"/>.</param>
  335.     ''' <param name="enabled">If set to <c>true</c>, enable dragging on the <see cref="Form"/>.</param>
  336.     ''' <param name="cursor">The <see cref="Cursor"/> used to drag the specified <see cref="Form"/>.</param>
  337.     ''' <exception cref="System.ArgumentException">The specified form is already added.;form</exception>
  338.     Public Function AddForm(ByVal form As Form,
  339.                             Optional enabled As Boolean = False,
  340.                             Optional cursor As Cursor = Nothing) As FormDragInfo
  341.  
  342.         For Each formInfo As FormDragInfo In Me.forms1
  343.  
  344.             If formInfo.Form.Equals(form) Then
  345.                 Throw New ArgumentException("The specified form is already added.", "form")
  346.                 Exit Function
  347.             End If
  348.  
  349.         Next formInfo
  350.  
  351.         Dim newFormInfo As New FormDragInfo(form) With {.Enabled = enabled, .Cursor = cursor}
  352.         Me.forms1 = Me.forms1.Concat({newFormInfo})
  353.         Me.AssocHandlers(form)
  354.  
  355.         Return newFormInfo
  356.  
  357.     End Function
  358.  
  359.     ''' <summary>
  360.     ''' Removes the specified <see cref="Form"/> from the draggable <see cref="Forms"/> collection.
  361.     ''' </summary>
  362.     ''' <param name="form">The form.</param>
  363.     ''' <exception cref="System.ArgumentException">The specified form is not found.;form</exception>
  364.     Public Sub RemoveForm(ByVal form As Form)
  365.  
  366.         Dim formInfoToRemove As FormDragInfo = Nothing
  367.  
  368.         For Each formInfo As FormDragInfo In Me.forms1
  369.  
  370.             If formInfo.Form.Equals(form) Then
  371.                 formInfoToRemove = formInfo
  372.                 Exit For
  373.             End If
  374.  
  375.         Next formInfo
  376.  
  377.         If formInfoToRemove IsNot Nothing Then
  378.  
  379.             Me.forms1 = From formInfo As FormDragInfo In Me.forms1
  380.                         Where Not formInfo Is formInfoToRemove
  381.  
  382.             formInfoToRemove.Enabled = False
  383.             Me.DeassocHandlers(formInfoToRemove.Form)
  384.  
  385.         Else
  386.             Throw New ArgumentException("The specified form is not found.", "form")
  387.  
  388.         End If
  389.  
  390.     End Sub
  391.  
  392.     ''' <summary>
  393.     ''' Finds the <see cref="FormDragInfo"/> instance that is associated with the specified <see cref="Form"/> reference.
  394.     ''' </summary>
  395.     ''' <param name="form">The <see cref="Form"/>.</param>
  396.     ''' <returns>The <see cref="FormDragInfo"/> instance that is associated with the specified <see cref="Form"/> reference.</returns>
  397.     Public Function FindFormDragInfo(ByVal form As Form) As FormDragInfo
  398.  
  399.         Return (From formInfo As FormDragger.FormDragInfo In Me.forms1
  400.                 Where formInfo.Form Is form).FirstOrDefault
  401.  
  402.     End Function
  403.  
  404.     ''' <summary>
  405.     ''' Finds the <see cref="FormDragInfo"/> instance that is associated with the specified <see cref="Form"/> reference.
  406.     ''' </summary>
  407.     ''' <param name="name">The <see cref="Form"/> name.</param>
  408.     ''' <returns>The <see cref="FormDragInfo"/> instance that is associated with the specified <see cref="Form"/> reference.</returns>
  409.     Public Function FindFormDragInfo(ByVal name As String,
  410.                                      Optional stringComparison As StringComparison =
  411.                                               StringComparison.OrdinalIgnoreCase) As FormDragInfo
  412.  
  413.         Return (From formInfo As FormDragger.FormDragInfo In Me.forms1
  414.                 Where formInfo.Name.Equals(name, stringComparison)).FirstOrDefault
  415.  
  416.     End Function
  417.  
  418. #End Region
  419.  
  420. #Region " Private Methods "
  421.  
  422.     ''' <summary>
  423.     ''' Associates the <see cref="Form"/> handlers to enable draggable operations.
  424.     ''' </summary>
  425.     ''' <param name="form">The form.</param>
  426.     Private Sub AssocHandlers(ByVal form As Form)
  427.  
  428.         AddHandler form.MouseDown, AddressOf Me.Form_MouseDown
  429.         AddHandler form.MouseUp, AddressOf Me.Form_MouseUp
  430.         AddHandler form.MouseMove, AddressOf Me.Form_MouseMove
  431.         AddHandler form.MouseEnter, AddressOf Me.Form_MouseEnter
  432.         AddHandler form.MouseLeave, AddressOf Me.Form_MouseLeave
  433.  
  434.     End Sub
  435.  
  436.     ''' <summary>
  437.     ''' Deassociates the <see cref="Form"/> handlers to disable draggable operations.
  438.     ''' </summary>
  439.     ''' <param name="form">The form.</param>
  440.     Private Sub DeassocHandlers(ByVal form As Form)
  441.  
  442.         If Not form.IsDisposed AndAlso Not form.Disposing Then
  443.  
  444.             RemoveHandler form.MouseDown, AddressOf Me.Form_MouseDown
  445.             RemoveHandler form.MouseUp, AddressOf Me.Form_MouseUp
  446.             RemoveHandler form.MouseMove, AddressOf Me.Form_MouseMove
  447.             RemoveHandler form.MouseEnter, AddressOf Me.Form_MouseEnter
  448.             RemoveHandler form.MouseLeave, AddressOf Me.Form_MouseLeave
  449.  
  450.         End If
  451.  
  452.     End Sub
  453.  
  454.     ''' <summary>
  455.     ''' Return the new location.
  456.     ''' </summary>
  457.     ''' <param name="formInfo">
  458.     ''' The <see cref="FormDragInfo"/> instance
  459.     ''' that contains the <see cref="Form"/> reference and its draggable info.
  460.     ''' </param>
  461.     ''' <param name="mouseCoordinates">The current mouse coordinates.</param>
  462.     ''' <returns>The new location.</returns>
  463.     Private Function GetNewLocation(ByVal formInfo As FormDragInfo,
  464.                                     ByVal mouseCoordinates As Point) As Point
  465.  
  466.         Return New Point(formInfo.InitialLocation.X + (mouseCoordinates.X - formInfo.InitialMouseCoords.X),
  467.                          formInfo.InitialLocation.Y + (mouseCoordinates.Y - formInfo.InitialMouseCoords.Y))
  468.  
  469.     End Function
  470.  
  471. #End Region
  472.  
  473. #Region " Hidden Methods "
  474.  
  475.     ''' <summary>
  476.     ''' Serves as a hash function for a particular type.
  477.     ''' </summary>
  478.     <EditorBrowsable(EditorBrowsableState.Never)>
  479.     Public Shadows Function GetHashCode() As Integer
  480.         Return MyBase.GetHashCode
  481.     End Function
  482.  
  483.     ''' <summary>
  484.     ''' Gets the System.Type of the current instance.
  485.     ''' </summary>
  486.     ''' <returns>The exact runtime type of the current instance.</returns>
  487.     <EditorBrowsable(EditorBrowsableState.Never)>
  488.     Public Shadows Function [GetType]() As Type
  489.         Return MyBase.GetType
  490.     End Function
  491.  
  492.     ''' <summary>
  493.     ''' Determines whether the specified System.Object instances are considered equal.
  494.     ''' </summary>
  495.     <EditorBrowsable(EditorBrowsableState.Never)>
  496.     Public Shadows Function Equals(ByVal obj As Object) As Boolean
  497.         Return MyBase.Equals(obj)
  498.     End Function
  499.  
  500.     ''' <summary>
  501.     ''' Determines whether the specified System.Object instances are the same instance.
  502.     ''' </summary>
  503.     <EditorBrowsable(EditorBrowsableState.Never)>
  504.     Private Shadows Sub ReferenceEquals()
  505.     End Sub
  506.  
  507.     ''' <summary>
  508.     ''' Returns a String that represents the current object.
  509.     ''' </summary>
  510.     <EditorBrowsable(EditorBrowsableState.Never)>
  511.     Public Shadows Function ToString() As String
  512.         Return MyBase.ToString
  513.     End Function
  514.  
  515. #End Region
  516.  
  517. #Region " Event Handlers "
  518.  
  519.     ''' <summary>
  520.     ''' Handles the MouseEnter event of the Form.
  521.     ''' </summary>
  522.     ''' <param name="sender">The source of the event.</param>
  523.     ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  524.     Private Sub Form_MouseEnter(ByVal sender As Object, ByVal e As EventArgs)
  525.  
  526.         Dim formInfo As FormDragInfo = FindFormDragInfo(DirectCast(sender, Form))
  527.  
  528.         formInfo.OldCursor = formInfo.Form.Cursor
  529.  
  530.         If formInfo.Enabled Then
  531.             formInfo.Form.Cursor = formInfo.Cursor
  532.             ' Optional:
  533.             ' formInfo.Form.BringToFront()
  534.         End If
  535.  
  536.     End Sub
  537.  
  538.     ''' <summary>
  539.     ''' Handles the MouseLeave event of the Form.
  540.     ''' </summary>
  541.     ''' <param name="sender">The source of the event.</param>
  542.     ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  543.     Private Sub Form_MouseLeave(ByVal sender As Object, ByVal e As EventArgs)
  544.  
  545.         Dim formInfo As FormDragInfo = FindFormDragInfo(DirectCast(sender, Form))
  546.  
  547.         formInfo.Form.Cursor = formInfo.OldCursor
  548.  
  549.     End Sub
  550.  
  551.     ''' <summary>
  552.     ''' Handles the MouseDown event of the Form.
  553.     ''' </summary>
  554.     ''' <param name="sender">The source of the event.</param>
  555.     ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
  556.     Private Sub Form_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
  557.  
  558.         Dim formInfo As FormDragInfo = FindFormDragInfo(DirectCast(sender, Form))
  559.  
  560.         If formInfo.Enabled Then
  561.             formInfo.DragInfo = New FormDragger(formInfo, Form.MousePosition, formInfo.Form.Location)
  562.         End If
  563.  
  564.     End Sub
  565.  
  566.     ''' <summary>
  567.     ''' Handles the MouseMove event of the Form.
  568.     ''' </summary>
  569.     ''' <param name="sender">The source of the event.</param>
  570.     ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
  571.     Private Sub Form_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
  572.  
  573.         Dim formInfo As FormDragInfo = FindFormDragInfo(DirectCast(sender, Form))
  574.  
  575.         If formInfo.Enabled AndAlso (formInfo.DragInfo IsNot FormDragger.Empty) Then
  576.             formInfo.Form.Location = formInfo.DragInfo.GetNewLocation(formInfo, Form.MousePosition)
  577.         End If
  578.  
  579.     End Sub
  580.  
  581.     ''' <summary>
  582.     ''' Handles the MouseUp event of the Form.
  583.     ''' </summary>
  584.     ''' <param name="sender">The source of the event.</param>
  585.     ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
  586.     Private Sub Form_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
  587.  
  588.         Dim formInfo As FormDragInfo = FindFormDragInfo(DirectCast(sender, Form))
  589.  
  590.         formInfo.DragInfo = FormDragger.Empty
  591.  
  592.     End Sub
  593.  
  594. #End Region
  595.  
  596. #Region " IDisposable "
  597.  
  598.     ''' <summary>
  599.     ''' To detect redundant calls when disposing.
  600.     ''' </summary>
  601.     Private isDisposed As Boolean = False
  602.  
  603.     ''' <summary>
  604.     ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  605.     ''' </summary>
  606.     Public Sub Dispose() Implements IDisposable.Dispose
  607.         Me.Dispose(True)
  608.         GC.SuppressFinalize(Me)
  609.     End Sub
  610.  
  611.     ''' <summary>
  612.     ''' Releases unmanaged and - optionally - managed resources.
  613.     ''' </summary>
  614.     ''' <param name="IsDisposing">
  615.     ''' <c>true</c> to release both managed and unmanaged resources;
  616.     ''' <c>false</c> to release only unmanaged resources.
  617.     ''' </param>
  618.     Protected Sub Dispose(ByVal isDisposing As Boolean)
  619.  
  620.         If Not Me.isDisposed Then
  621.  
  622.             If isDisposing Then
  623.  
  624.                 For Each formInfo As FormDragInfo In Me.forms1
  625.  
  626.                     With formInfo
  627.  
  628.                         .Enabled = False
  629.                         .OldCursor = Nothing
  630.                         .DragInfo = FormDragger.Empty
  631.                         .InitialMouseCoords = Point.Empty
  632.                         .InitialLocation = Point.Empty
  633.  
  634.                         Me.DeassocHandlers(.Form)
  635.  
  636.                     End With ' form
  637.  
  638.                 Next formInfo
  639.  
  640.                 Me.forms1 = Nothing
  641.  
  642.             End If ' IsDisposing
  643.  
  644.         End If ' Not Me.IsDisposed
  645.  
  646.         Me.isDisposed = True
  647.  
  648.     End Sub
  649.  
  650. #End Region
  651.  
  652. End Class
  653.  
  654. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement