Copy, Cut, Paste

T

Tom Spink

Hi, this is a very broad question... Please tell us what you'd like to
Cut/Copy/Paste...

e.g. Files/Images/Text/etc

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
J

John

Sorry, I just want to provide the Edit menu's copy, cut paste functionality.

Thanks

Regards
 
J

John

If I want to implement it in the generic way (Edit->Copy) what would be the
value of data in System.Windows.Forms.Clipboard.SetDataObject(data)?
Thanks

Regards
 
T

Tom Spink

Hi, what do you want in there?

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
J

John

Whatever test the user has selected at the time (it is a database app). I
would not know which field it would be beforehand.

Thanks

Regards
 
A

Armin Zingler

John said:
Whatever test the user has selected at the time (it is a database
app). I would not know which field it would be beforehand.

You can get the active Form using Form.ActiveForm or ActiveMdiChild in an
Mdi container. The ActiveControl returns the active control, and depending
on the type of the active control you can copy the selected text or
whatever. For example, if the active control is a Datagrid, you can copy the
selected text of the active cell.

In all Forms I'd probably implement an Interface that handles the clipboard
features for the Form.
 
A

Armin Zingler

Armin Zingler said:
You can get the active Form using Form.ActiveForm or ActiveMdiChild
in an Mdi container. The ActiveControl returns the active control,
and depending on the type of the active control you can copy the
selected text or whatever. For example, if the active control is a
Datagrid, you can copy the selected text of the active cell.

In all Forms I'd probably implement an Interface that handles the
clipboard features for the Form.

Some example code for you.... attention: Untested! :)


Public Interface ISupportsClipboard
Enum Action
Copy
Cut
Delete
Paste
End Enum

Function ActionAvailable(ByVal Action As Action) As Boolean
Sub PerformAction(ByVal Action As Action)
End Interface


In the Form, implement ISupportsClipboard:

Public Function ActionAvailable( _
ByVal Action As ISupportsClipboard.Action) As Boolean _
Implements ISupportsClipboard.ActionAvailable

Return TypeOf Me.ActiveControl Is TextBox AndAlso _
DirectCast(Me.ActiveControl, TextBox).SelectionLength > 0 AndAlso _
(Action <> ISupportsClipboard.Action.Paste OrElse _
Clipboard.GetDataObject.GetDataPresent(GetType(String)))

End Function

Public Sub PerformAction( _
ByVal Action As ISupportsClipboard.Action) _
Implements ISupportsClipboard.PerformAction

If Not Me.ActionAvailable(Action) Then
Throw New InvalidOperationException( _
"The clipboard action '" & Action.ToString & "' is not available."
_
)
End If

Dim txt As TextBox
txt = DirectCast(Me.ActiveControl, TextBox)

If Action = ISupportsClipboard.Action.Copy OrElse _
Action = ISupportsClipboard.Action.Cut Then

Clipboard.SetDataObject(txt.SelectedText)
End If

If Action = ISupportsClipboard.Action.Cut OrElse _
Action = ISupportsClipboard.Action.Delete Then
txt.SelectedText = ""
ElseIf Action = ISupportsClipboard.Action.Paste Then
txt.SelectedText =
Clipboard.GetDataObject.GetData(GetType(String)).ToString
End If

End Sub
 
J

John

when I right click in a text field it gives me the cut/copy/paste context
menu. cannot I tap into this built-in functionality?

Regards
 
H

Herfried K. Wagner [MVP]

* "John said:
when I right click in a text field it gives me the cut/copy/paste context
menu. cannot I tap into this built-in functionality?

Please be more specific. What exactly do you want to do for which
type(s) of control(s)?
 
E

Erik Frey

Herfried K. Wagner said:
Please be more specific. What exactly do you want to do for which
type(s) of control(s)?

I think he is referring to the fact that most windows controls natively
support cut/copy/paste messages - all you have to do is send the appropriate
message with the win32 api. Like this:

http://www.geocities.com/practicalvb/vb/controls/textboxops.html

I'm a bit surprised MS only implements this functionality in
TextBoxBase, and not at a higher level...

Erik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top