Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run cut and paste in VB

Status
Not open for further replies.

hilliolouis

Programmer
Jul 22, 2005
51
GB
New to VB.net, made a tool strip at top and had it populate its self with defaults, but the print, cut, copy and paste buttons do not actually do anything. What is the VB for this? Any help appriciated.

Louis Hill
 
Not sure if this is what you need, but here is some code I had to use to allow copy and paste into a textbox.
Code:
Private Enum j2aEditActions As Integer
    None
    Cut
    Copy
    Paste
End Enum 'j2aEditActions

'NOTE: This Function DOES NOT fire if PreProcessMessage is OverRidden
' Function traps Ctrl-V and Shift-Ins pastes, changing clipboard contents to plain text.
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
    ByVal keyData As System.Windows.Forms.Keys) As Boolean
    Dim text, test, testName As String
    Dim replacementChar As Char = Nothing
    Dim editAction As j2aEditActions = j2aEditActions.None
    Dim iData As IDataObject = 
        System.Windows.Forms.Clipboard.GetDataObject()

    If True Then ' glw4 mbRemoveFormattingOnPaste Then
        If msg.Msg = WM_KEYDOWN Or msg.Msg = WM_SYSKEYDOWN Then
            Select Case keyData
                Case Keys.Control Or Keys.V
                    editAction = j2aEditActions.Paste
                Case Keys.Shift Or Keys.Insert
                    editAction = j2aEditActions.Paste
                Case Keys.Control Or Keys.C
                    editAction = j2aEditActions.Copy
                Case Keys.Control Or Keys.X
                    editAction = j2aEditActions.Cut
                    'Case Keys.Delete
            End Select
        End If
    End If

    Select Case editAction
        Case j2aEditActions.Paste
            'DataFormats.Text and DataFormats.StringFormat appear to be synonymous
            If Not Clipboard.GetDataObject Is Nothing Then
                If Clipboard.GetDataObject().GetDataPresent(DataFormats.Text, True) Then
                    ' Attempt to convert clipboard data to text
                    Clipboard.SetDataObject(Clipboard.GetDataObject.GetData(DataFormats.Text, True))
                    ' Ensure clipboard data is text
                    If iData.GetDataPresent(DataFormats.Text) Then

                        'Ensure clipboard data is numeric
                        Dim resultText As String = String.Empty
                        Dim errorFound As Boolean, reset As Boolean = False
                        text = CType(iData.GetData(DataFormats.Text), String).Trim
                        text = ConvertFromScientificNotation(text, IsRealNumber, errorFound, (Me.RightToLeft = RightToLeft.Yes)).ToString
                        For i As Integer = 0 To text.Length - 1
                            If Not ValidData(Nothing, reset, resultText, test, testName, replacementChar, True, text.Substring(i, 1)) Then
                                MsgBox("Clipboard data '" & text & "' cannot be pasted because it is either not numeric or has failed one or more limit tests", MsgBoxStyle.Information, "Invalid Clipboard Data")
                                errorFound = True
                                Exit For
                            End If
                        Next

                        If Not errorFound Then
                            If reset Then
                                resultText = StripGroupSeparator(resultText, IsRealNumber, m_GroupSep).ToString
                            End If

                            Dim start As Integer
                            Dim exception As Exception
                            Dim messageType As j2aMessageTypes

                            'Insert validated text and ensure limits are not exceeded
                            start = Me.SelectionStart
                            text = Me.Text.Substring(0, Me.SelectionStart) & resultText & Me.Text.Substring(Me.SelectionStart + Me.SelectionLength)
                            'text = Me.Text.Substring(0, Me.SelectionStart) & "~" & resultText & "~" & Me.Text.Substring(Me.SelectionStart + Me.SelectionLength)
                            'If Not ValidateValue(text.Replace("~"c, String.Empty), testName, exception, messageType, , m_RangeErrors, m_TypeRangeErrors, m_PrecisionErrors, m_TypePrecisionErrors, m_WholeDigitsErrors, m_DecimalDigitsErrors) Then
                            If Not m_LimitsEvaluator.ValidateValue(text, testName, exception, messageType, , m_RangeErrors, m_TypeRangeErrors, m_PrecisionErrors, m_TypePrecisionErrors, m_WholeDigitsErrors, m_DecimalDigitsErrors) Then   'glw4
                                If Not exception Is Nothing Then
                                    If Not OnMessageExceptionEvent(String.Empty, j2aMessageTypes.GenericMinMax, text, GetFormattedExceptionString(exception, MethodBase.GetCurrentMethod), j2aExceptionResponses.WarnDiscard) Then Return False
                                    End If
                                If Not OnMessageExceptionEvent(String.Empty, messageType, text) Then
                                    MsgBox("Combined clipboard data '" & text.Replace("~"c, "' '") & "' cannot be pasted because it has failed one or more limit tests", MsgBoxStyle.Information, "Invalid Clipboard Data")
                                    Return False
                                End If
                            End If
                            'Strip error message formatting
                            'text = text.Replace("~"c, String.Empty)
                            Me.Text = text
                            Me.SelectionStart = start
                            m_Value = GetValue(Me.Text)
                        End If
                    End If
                End If
            End If
        Case j2aEditActions.Copy
            If Me.SelectionLength = 0 Then Return False
            Clipboard.SetDataObject(Me.SelectedText)
        Case j2aEditActions.Cut
            If Me.SelectionLength = 0 Then Return False
            Dim start As Integer = Me.SelectionStart
            Clipboard.SetDataObject(Me.SelectedText)
            'Strip the selected text out
            Me.Text = Me.Text.Substring(0, Me.SelectionStart) & Me.Text.Substring(Me.SelectionStart + Me.SelectionLength)
            Me.SelectionLength = 0
            Me.SelectionStart = start
    End Select

    Return MyBase.ProcessCmdKey(msg, keyData)
End Function

Have a great day!

j2consulting@yahoo.com
 
will have a look through thoughrly tomorrow. Thanks.

Louis Hill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top