Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2015. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Text Editor
- '
- ' Author: Joseph L. Bolen
- ' Date Created: Feb 2015
- '
- ' Description: Simple plain text editor program with printing ability.
- '
- ' Documentation is at:
- ' App's screen image is at: http://imgur.com/TzWs9kO
- ' App's screen design time specs at: http://pastebin.com/bhinRQ5d
- ' App's Visual Basic .NET Drag and Drop is at
- ' http://pastebin.com/yWB22inT
- ' App's Visual Basic .NET code is at http://pastebin.com/u/jaybeeoh
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '
- ' See Also, MSDN's article "Implementing Drag and Drop in Visual Basic .NET"
- ' at http://msdn.microsoft.com/en-us/library/aa289508(v=vs.71).aspx .
- '-------------------------------------------------------------------------------------------
- #Region " Declare class level variables"
- ' NOTE: Additional code not shown.
- ' For Drag and Drop.
- Private mouseIsDown As Boolean = False
- Private textToMove As String = String.Empty
- Private textToMoveStart As Integer
- #End Region
- #Region " Drag and Drop"
- ' Note: Set at design time, MyTextBox.AllowDrop = True
- ' Mouse Down key has been pressed.
- Private Sub MyTextBox_MouseDown(sender As Object, e As MouseEventArgs) _
- Handles MyTextBox.MouseDown
- ' Internal drag and drop.
- With MyTextBox
- If (.SelectionLength > 0) Then
- textToMove = .SelectedText
- textToMoveStart = .SelectionStart
- mouseIsDown = True
- End If
- End With
- End Sub
- ' Initiate internal dragging.
- Private Sub MyTextBox_MouseMove(sender As Object, e As MouseEventArgs) _
- Handles MyTextBox.MouseMove
- ' If dragging, set DragDropEffects.
- With MyTextBox
- If mouseIsDown AndAlso (.SelectionLength > 0) Then
- .DoDragDrop(.SelectedText, DragDropEffects.Copy Or DragDropEffects.Move)
- End If
- End With
- mouseIsDown = False
- End Sub
- 'Scroll to insertion point position.
- Private Sub MyTextBox_DragOver(sender As Object, e As DragEventArgs) _
- Handles MyTextBox.DragOver
- ' Determine cursor location, then scroll to position.
- With MyTextBox
- .Select((.GetCharIndexFromPosition(.PointToClient(Cursor.Position))), 0)
- .ScrollToCaret()
- .Focus()
- End With
- End Sub
- ' Show DragDropEffect.
- Private Sub MyTextBox_DragEnter(sender As Object, e As DragEventArgs) _
- Handles MyTextBox.DragEnter
- ' Check the format of the data being dropped.
- If (e.Data.GetDataPresent(DataFormats.Text)) Then
- If (e.KeyState And 8) = 8 AndAlso (e.AllowedEffect And DragDropEffects.Copy) = DragDropEffects.Copy Then
- ' CTL KeyState for copy.
- e.Effect = DragDropEffects.Copy
- Else
- e.Effect = DragDropEffects.Move
- End If
- Else
- e.Effect = DragDropEffects.None
- End If
- End Sub
- ' Drop text at current cursor location.
- Private Sub MyTextBox_DragDrop(sender As Object, e As DragEventArgs) _
- Handles MyTextBox.DragDrop
- With MyTextBox
- ' Determine cursor location, then insert data.
- Dim index As Integer = .GetCharIndexFromPosition(.PointToClient(Cursor.Position))
- .Text = .Text.Insert(index, e.Data.GetData(DataFormats.Text).ToString)
- ' If internal move operation, then delete data from previous location.
- If (e.Effect = DragDropEffects.Move) AndAlso (textToMove <> String.Empty) Then
- Dim foundPositon As Integer = .Text.IndexOf(textToMove, textToMoveStart, StringComparison.OrdinalIgnoreCase)
- If foundPositon > -1 Then
- .Select(foundPositon, textToMove.Length)
- .SelectedText = String.Empty
- ' Reposition index.
- If foundPositon <= index Then
- index -= textToMove.Length
- End If
- If index < 0 Then
- index = 0
- End If
- End If
- End If
- ' Highlight new or moved data.
- .Select(index, e.Data.GetData(DataFormats.Text).ToString.Length)
- .ScrollToCaret()
- .Focus()
- .Modified = True
- textToMove = String.Empty
- textToMoveStart = 0
- End With
- End Sub
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment